remove subsequent identical lines only when matching a pattern in bash

Viewed 57

Here an example of what my sh output look like

abc
abc
abc
rty // uio
rty // uio
fgh
fgh jkl
...

What I want in my output is

abc
abc
abc
rty // uio
fgh
fgh jkl
...

I would like to remove just one of the double lines with //. All duplicated lines (with // or not) are following each other.

I can't find something with cut, awk, sed, or even sort -u and uniq.

1 Answers

There is probably a simpler way of doing it, but here is a start with awk:

$ awk '!/\/\// || /\/\// && !seen[$0]++' file
abc
abc
abc
rty // uio
fgh
fgh jkl
...
Related