Issue
I am trying to find the line number of the first occurrence of two consecutive lines having the same value of "null".
Input:
It's My Life - Bon Jovi
It's My Life - Bon Jovi
It's My Life - Bon Jovi
null
When Doves Cry (Mixed) - Prince & The Revolution
When Doves Cry (Mixed) - Prince & The Revolution
When Doves Cry (Mixed) - Prince & The Revolution
The Sign - Ace of Base
The Sign - Ace of Base
null
null
null
null
null
null
null
It's Tricky - Run-DMC
It's Tricky - Run-DMC
The Tide Is High - Blondie
The Tide Is High - Blondie
null
null
null
Plush - Stone Temple Pilots
Plush - Stone Temple Pilots
In this case I would like to see "10" as an output as this is the line number of the line behind "The Sign - Ace of Base". That's the first time when two consecutive lines hold the value "null".
Here is what I have:
grep -n -A2 "null" trim.log | cut -f1 -d:
The output is:
4
5-When Doves Cry (Mixed) - Prince & The Revolution
6-When Doves Cry (Mixed) - Prince & The Revolution
--
10
11
12
13
14
15
16
17-It's Tricky - Run-DMC
18-It's Tricky - Run-DMC
--
21
22
23
24-Plush - Stone Temple Pilots
25-Plush - Stone Temple Pilots
Meaning it finds the pattern (indicated by "--", however, I can't get it to give me just the relevant line number of "10" as an Ouput.
Thanks in advance.
Solution
Using any awk:
$ awk '($0 == p) && (p == "null") { print NR-1; exit } {p=$0}' file
10
Answered By - Ed Morton Answer Checked By - Clifford M. (WPSolving Volunteer)