0

I want to replace the first occurrence of search pattern with something and rest with something else as:

aaa
bbb
ccccc
country
dddd
country
frrffr4
grtgt
gthth
country
dddrr

here I want country to be replaced. First occurence of countryshould be my_country and rest of the occurences with our_country as:

aaa
bbb
ccccc
my_country
dddd
our_country
frrffr4
grtgt
gthth
our_country
dddrr

Is there any command to do this?

4

1 回答 1

3

Try this:

awk 'BEGIN {r="my_country"} /country/ {print r; r="our_country"; next} {print}' 
于 2013-02-08T20:44:35.363 回答