user2809888
user2809888

Reputation:

delete everything before pattern including pattern using awk or sed

aaa aaaa aaaa aaaa
sss ssss ssss ssss
ddd dddd dddd dddd
fff ffff ffff ffff
abc pattern asd fde 
111 222 333 444 555
666 777 888 999 000

Desired output : If the

111 222 333 444 555
666 777 888 999 000

Upvotes: 7

Views: 16963

Answers (3)

fedorqui
fedorqui

Reputation: 289505

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

$ awk 'p; /pattern/ {p=1}' file
111 222 333 444 555
666 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.

Upvotes: 13

Kent
Kent

Reputation: 195029

sed '1,/pattern/d' file

works for your example.

sed '0,/pattern/d' file

is more reliable.

Upvotes: 8

sat
sat

Reputation: 14949

Another one sed solution:

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

Upvotes: 2

Related Questions