问题描述:

I need to strip-off the data which comes after space , slash /, greater than >, dot .. I only need to display the part before the space, slash, dot, greater than symbol in given string data using a shell or Perl script.

ex:

a15-ap-5035.wma.ibm.com

a15-ap-99995/wma.ibm.com

a15-ap-99995>wma.ibm.com

网友答案:

In shell you can do string manipulation:

s='a15-ap-99995>wma.ibm.com'
echo "${s/[,\/. >]*/}"
a15-ap-99995>wma

s='a15-ap-5035.wma.ibm.com'
echo "${s/[,\/. >]*/}"
a15-ap-5035

Using `perl:

perl -pe 's~[,/>. ].*~~' <<< "$s"
网友答案:

stripoff the data which comes after space, slash (/), greater than (>),(.),

In Perl it would be like,

$str =~ s/[\/\s>.].*//;
网友答案:

Using Bash Parameter Expansion:

s="a15-ap-5035.wma.ibm.com"
echo "${s%%[./> ]*}"
相关阅读:
Top