Jason
Jason

Reputation: 2492

Remove everything before a blank line using sed

Lets say I have a file which is something like this:

"Testing is important"

Nothing is impossible

The output should be:

Nothing is impossible

This means the sed removed everything before new line. Also, I need to make sure it works on bash on windows.

Please help.

Upvotes: 1

Views: 1378

Answers (3)

Tom Fenech
Tom Fenech

Reputation: 74635

To allow for more than one blank line and multiple lines after the final blank line, you could use something like this:

awk 'BEGIN{RS=ORS=""}{a=$0}END{print a}' file

This unsets the Record Separator RS, so that each block/paragraph is treated as a separate record. It assigns each record to the variable a, then prints the last value of a once the file has been processed. The Output Record Separator ORS is also unset, so that no newline is appended to the final block.

Upvotes: 0

josifoski
josifoski

Reputation: 1726

You can try this

sed '1,/^\s*$/d' file  

\s is whitespace, it's same with

sed '1,/^[[:blank:]]*$/d' file  

Upvotes: 6

that other guy
that other guy

Reputation: 123480

Sed supports addressing lines both as numbers and as matching regex. In your case, you can delete all lines starting from 1, and ending with an empty line:

sed -e '1,/^$/d'

On Windows your files may contain contain carriage returns, in which case you can use:

sed -e '1,/^\r*$/d'

(assuming GNU sed)

Upvotes: 3

Related Questions