user1611908
user1611908

Reputation:

Need to replace duplicates in file except if the line matches a pattern

My questions is fairly simple. I have a file containing lines which are often duplicates of one another. My first attempt used awk: cat /tmp/log |awk '!x[$0]++'|.

That does the job perfectly except that I realized there was one line that I need to have duplicated.

So basically I need to remove all duplicates except for one that contains "Successful association". Even if it is a dupe.

Any ideas are welcome!

Upvotes: 1

Views: 84

Answers (1)

perreal
perreal

Reputation: 97968

Print the line if not seen before or it equals to the allowed duplicate:

awk '!x[$0]++ || ($0 ~ /Successful association/)' /tmp/log

Upvotes: 2

Related Questions