delete everything before pattern including pattern using awk or sed delete everything before pattern including pattern using awk or sed unix unix

delete everything before pattern including pattern using awk or sed


Just set a flag whenever the pattern is found. From that moment on, print the lines:

$ awk 'p; /pattern/ {p=1}' file111 222 333 444 555666 777 888 999 000

Or also

awk '/pattern/ {p=1;next}p' file

It looks for pattern in each line. When it is found, the variable p is set to 1. The tricky point is that lines are just printed when p>0, so that the following lines will be printed.

This is a specific case of How to select lines between two patterns? when there is no such second pattern.


sed '1,/pattern/d' file

works for your example.

sed '0,/pattern/d' file

is more reliable.


Another one sed solution:

sed ':loop;/pattern/{d};N;b loop' file.txt