I need to match the end of a file after a word match in bash. I have a text like this:
line 1
line 2
line 3
key line
line 5
line 6
I pretend to get everything after "key line", so my output would be:
line 5
line 6
How can I do this using bash?
I've tried grep -o -P '(?<=key line\n)[\s\S]*'
but it didn't work, although it worked testing in https://regexr.com/
CodePudding user response:
grep
is line-based. It doesn't work well when you want to search across lines.
sed
is up for the job. This will d
elete all lines from line 1
to the one containing key line
, leaving only the lines after it:
$ sed '1,/key line/d' test.txt
line 5
line 6