I want to print the countries which which have to after ~:.welcome~:to~:Germanywelcome~:no please~:Italywelcome~:to~:Brazilwelcome~:not ok~:ChinaNote: 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:toGermanyno pleaseItalytoBrazilnot okChinaHow to filter countries other than to.UPDATE:Alternative solution:(Figured out with cut) :-)grep -v to |cut -d ':' -f3 
filter based on a field value in awk
text processing;awk
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; }' fileResult:GermanyBrazil