4

I want to print the countries which which have to after ~:.

welcome~:to~:Germany
welcome~:no please~:Italy
welcome~:to~:Brazil
welcome~:not ok~:China

Note: I do not know what will be there other than "to". It can be anything and can be changed (like no please, not ok).

I am tried using cut, awk, sed. But I am unable to figure out.

awk -F "~:" '{print $2 $NF}'

But I get output like:

toGermany
no pleaseItaly
toBrazil
not okChina

How to filter countries other than to.

UPDATE:

Alternative solution:(Figured out with cut) :-)

grep -v "to" |cut -d ':' -f3 

2 Answers 2

5

As you are using ~: as field separator you can check if second field is equal to to and to print third field which is the country:

awk -F"~:" '$2 == "to" { print $3; }' file

Result:

Germany
Brazil
0
2

Do not forget sed solution:

sed -n '/~:to~:/s/.*://p'

or more qiuck (may be)

sed '/~:/{s/to~:/\n/;D}'
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .