Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

grep

sed

awk

Can anyone help me figure out how to do this, it would be much appreciated.

example

block of            //delete
non-important text  //delete

important text      //keep
more important text //keep
like image 283
Marz157 Avatar asked Feb 13 '12 03:02

Marz157


People also ask

How will you remove blank lines from a file using grep in SED?

The d command in sed can be used to delete the empty lines in a file. Here the ^ specifies the start of the line and $ specifies the end of the line. You can redirect the output of above command and write it into a new file.

How do I skip blank lines in awk?

We can remove blank lines using awk: $ awk NF < myfile.

What command you will use for removing unnecessary blank lines from a file's content?

Using awk. Using the awk command, we can remove blank lines in different ways.


1 Answers

sed '1,/^$/d' file

or

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

Output

$ 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
like image 166
SiegeX Avatar answered Oct 03 '22 11:10

SiegeX