0

I have this input:

Host: ping.chartbeat.net
Host: extra.test.co
userblablabla
Host: extra.test.co
Host: extra.test.co
Host: extra.test.co
Host: extra.test.co
Host: extra.test.co
Host: extra.test.co
Host: extra.test.co
Host: extra.test.co
Host: secure.test.com
userlalalalala
Host: ping.chartbeat.net
Host: secure.test.com
Host: secure.test.com
Host: secure.test.com

and I want to convert it into this:

Host: ping.chartbeat.net
Host: extra.test.co
userblablabla
Host: secure.test.com
userlalalalala

How do I perform that¿?

I tried |sort -u but that breaks the order in which I want the lines

aDoN
  • 1,679
  • 4
  • 27
  • 48
  • Why is `Host: extra.test.co` repeated twice in the final output? and `Host: secure.test.com` is missing? – Inian Jun 11 '18 at 12:38
  • @Inian presumably they only want to remove lines when they are repeating the line directly above, not any further line already seen, but yes, the logic should be explained clearly rather than requiring people to infer/guess it. – underscore_d Jun 11 '18 at 12:41
  • 1
    Possible duplicate of [Unix: removing duplicate lines without sorting](https://stackoverflow.com/questions/11532157/unix-removing-duplicate-lines-without-sorting) – Davide Spataro Jun 11 '18 at 12:43
  • But then the second `Host: ping.chartbeat.net` and `Host: secure.test.com` would be missing. OP, please clarify. – Karsten Koop Jun 11 '18 at 12:53

1 Answers1

1

You want to use uniq <file>. uniq is part of the GNU coreutils.

andreee
  • 3,626
  • 16
  • 33