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
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.
We can remove blank lines using awk: $ awk NF < myfile.
Using awk. Using the awk command, we can remove blank lines in different ways.
sed '1,/^$/d' file
or
awk '!$0{f=1;next}f{print}' file
$ 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With