Sed or awk : pattern selection based on special characters

Hello All,

I am here again scratching my head on pattern selection with special characters.

I have a large file having around 200 entries and i have to select a single line based on a pattern.

I am able to do that:

Code:

 
cat mytest.txt | awk -F: '/myregex/ { print $2}'

Output is as below:

 
//mytestserver.bon.com

now i have to split this output and pass only

to a variable

i am trying this sed command ..but somehow this is not solving the purpose.

Any help where i am going wrong

 
cat mytest.txt | awk -F: '/myregex/ { print $2}' | sed 's/^[/  ^.]//'

Thanks
Usha

Please post the line from the input file that you're interested in.

echo '//mytestserver.bon.com' | sed -r 's //([^.]*).* \1 '
mytestserver

:wink:

1 Like

No need to cat mytest.txt...

awk -F: '/myregex/ { print $2}' mytest.txt | sed 's;/\{1,\};;'
1 Like
awk -F"[:/]" '/myregex/ { print $(NF-2)}' mytest.txt
1 Like

Hi,
Try this,

awk -F: '/myregex/ {gsub(/\//,"",$2);split($2,a,"."); print a[1];}' input_file

cheers,
Ranga:-)

1 Like

Thanks Ranga.. Its perfect...

Cheers,
Usha