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?

1 Answer 1

3

Try this:

awk 'BEGIN {r="my_country"} /country/ {print r; r="our_country"; next} {print}' 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.