Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove all lines before a match with sed

Tags:

sed

try this (GNU sed only):

sed '0,/^bin$/d'

..output is:

$sed '0,/^bin$/d' file
boot
...
sys
tmp
usr
var
vmlinuz

This sed command will print all lines after and including the matching line:

sed -n '/^WHATEVER$/,$p'

The -n switch makes sed print only when told (the p command).

If you don't want to include the matching line you can tell sed to delete from the start of the file to the matching line:

sed '1,/^WHATEVER$/d'

(We use the d command which deletes lines.)


you can also try with :

awk '/searchname/{p=1;next}{if(p){print}}'

EDIT(considering the comment from Joe)

awk '/searchname/{p++;if(p==1){next}}p' Your_File

I would insert a tag before a match and delete in scope /start/,/####tag####/.