CrudeCoder
CrudeCoder

Reputation: 401

Delete matching sequential rows

Currently I have a csv file like this:

11:00 p.m.
11:00 p.m.
03:00 p.m.
03:00 p.m.
05:00 a.m.
05:00 a.m.
07:00 a.m.
12:00 p.m.
07:00 a.m.
05:00 a.m.

I want to delete the duplicates that are in sequential rows so the output will be this:

11:00 p.m.
03:00 p.m.
05:00 a.m.
07:00 a.m.
12:00 p.m.
07:00 a.m.
05:00 a.m.

I do not want to delete all duplicates, just duplicates that are in sequential rows, for example if the 4th and 5th row match, delete one of the duplicate rows. Is there an easy way to do this without having to run a for-loop?

Upvotes: 1

Views: 90

Answers (2)

ray
ray

Reputation: 4267

Try uniq.

It can do what exactly you want to do.

Upvotes: 5

iruvar
iruvar

Reputation: 23384

With

awk '$0 != prev; {prev=$0}' file.txt

Upvotes: 4

Related Questions