I have a file where I have few lines of information that contains the country name as shown below.
$cat country.txt
max_china_clean_foo
man_india_raw_bar
max_us_clean_bax
max_uk_raw_bar
max_canada_raw_foo
max_au_clean_bar
I want to extract only the country names from this file. I am currently using the below code to extract country name in a for loop
val=${val#*_}
val=${val%_clean*}
echo $val
But the output produced has only china, us
and au
country names and hence I have to repeat the similar code with minor modifications to extract the remaining countries like below
val=${val#*_}
val=${val%_raw*}
echo $val
This is not a clear way of coding, I know and hence need your help to extract the country names from all the lines that has either clean
or raw
string in it.
Is there a way using awk or sed to extract all the country names with two match keys? My output should look like this
china
india
us
uk
canada
au