Reputation: 2492
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
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
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
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