Reputation: 962
I can't figure out how to grep
the lines I want in this file:
8.txt 07:34:12 -> CONTENT START
8.txt 07:34:42 <-CONTENT END
8.txt 07:35:08 -> CONTENT START
8.txt 07:36:33 <-CONTENT END
8.txt 07:57:51 -> CONTENT START
8.txt 07:57:52 -> CONTENT START
8.txt 07:58:25 <-CONTENT END
8.txt 07:58:36 -> CONTENT START
8.txt 07:59:24 <-CONTENT END
8.txt 08:20:23 -> CONTENT START
8.txt 08:21:22 <-CONTENT END
8.txt 08:22:44 -> CONTENT START
8.txt 07:34:12 -> CONTENT START
8.txt 08:23:07 <-CONTENT END
8.txt 08:26:35 -> CONTENT START
8.txt 08:27:24 <-CONTENT END
8.txt 08:29:53 -> CONTENT START
8.txt 08:30:28 <-CONTENT END
8.txt 08:30:59 -> CONTENT START
8.txt 08:31:21 <-CONTENT END
8.txt 08:48:28 -> CONTENT START
8.txt 08:48:56 <-CONTENT END
8.txt 09:13:10 -> CONTENT START
8.txt 09:13:40 <-CONTENT END
8.txt 09:13:52 -> CONTENT START
8.txt 09:14:44 <-CONTENT END
8.txt 09:19:50 -> CONTENT START
8.txt 09:20:28 <-CONTENT END
8.txt 09:27:04 -> CONTENT START
8.txt 09:27:40 <-CONTENT END
If CONTENT START
occurrence on consecutive lines then display them.
Output expected:
8.txt 07:57:51 -> CONTENT START
8.txt 07:57:52 -> CONTENT START
8.txt 08:22:44 -> CONTENT START
8.txt 07:34:12 -> CONTENT START
How can this be done?
Upvotes: 0
Views: 587
Reputation: 203684
You don't say what to do if CONTENT START appears on 3 consecutive lines so this may or may not be what you want:
awk -v s="CONTENT START" '$0~s && p~s{print p ORS $0} {p=$0}' file
Upvotes: 0
Reputation: 85805
This isn't a task for grep
use uniq
for this:
$ uniq -D -f4 file
8.txt 07:57:51 -> CONTENT START
8.txt 07:57:52 -> CONTENT START
8.txt 08:22:44 -> CONTENT START
8.txt 07:34:12 -> CONTENT START
The option -D
is for displaying the duplicated lines and -f4
skips the first four fields.
Upvotes: 4