Search This Blog

Tuesday, September 22, 2015

Bash - Get output after matching line

$ cat file.txt
line 1
line 2
this is the line
line 4
line 5

If you want lines starting from "this is the line"

$ cat file.txt | awk '/this is the line/{ f=1; } f'
this is the line
line 4
line 5

When the line is found, set f to 1.
The last 'f' is shortcut to 'f == 1 { print }'

If you want output after the matching line

$ cat file.txt | awk '/this is the line/{ f=1; next; } f'
line 4
line 5