Sed delete all the words before a match

sedtext processing

I want to delete all the words before a pattern for example: I want to delete all the words before STAC.

Input:

asd
asdd
asddd
STAC
asd
as

Output:

STAC
asd
as

I have this code sed -ni "s/^.*STAC//d" myfile

Best Answer

sed works linewise, that's why your try will not work.

So how to do it with sed? Define an address range, starting from the STAC line (/^STAC$/) to the end of the file ($). Those should be printed, so everything else (!) should get deleted:

sed -i '/^STAC$/,$!d' myfile
Related Question