Use sed / grep / awk to delete everything up to the first empty line

Can someone help me figure out how to do this would be very grateful.

Example

block of //delete non-important text //delete important text //keep more important text //keep 
+4
source share
4 answers
 sed '1,/^$/d' file 

or

 awk '!$0{f=1;next}f{print}' file 

Exit

 $ sed '1,/^$/d' <<< $'block of\nnon-important text\n\nimportant text\nmore important text' important text more important text $ awk '!$0{f=1;next}f{print}' <<< $'block of\nnon-important text\n\nimportant text\nmore important text' important text more important text 
+10
source

If the empty string is empty, this will do the following:

 sed '1,/^$/d' filename 
+5
source

with awk:

 awk "BEGIN { x = 0 } /^$/ { x = 1} { if (x == 2) { print } ; if (x == 1) { x = 2 } }" filename 
0
source

Another option with grep (works on strings)

 grep -v PATTERN filename > newfilename 

For instance:

filename has the following lines:

 this is not implicated but important text this is not important text this is important text he says not important text he says not this it is more important text 

Filter:

 grep -v "not imp" filename > newfilename 

will create newfilename with the following three lines:

 this is not implicated but important text this is important text he says not this it is more important text 

You will need to select PATTERN, which uniquely identifies the lines you are trying to delete. If you use PATTERN from "important text" , it will match all lines, and "not imp" matches only lines that contain the words "not imp" . Use egrep (or grep -E ) for regexp filters if you want more flexibility when matching with a pattern.

0
source

Source: https://habr.com/ru/post/1396110/


All Articles