Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

sed one liner to Delete blank lines - Help required

$
0
0
Hi,

Code:

cat test.txt
BlankLine
BlankLine
BlankLine
BlankLine
ello
hi
helo
BlankLine
BlankLine
heylo
BlankLine
BlankLine
BlankLine
done
BlankLine
BlankLine
BlankLine

The above is the content of the file.(blank lines in between lines,at the begining of file and at the end of the file)

I am applying the following sed command

Code:

sed '/^$/N;/\n$/D' test.txt
the output is

Code:

BlankLine
ello
hi
helo
BlankLine
heylo
BlankLine
done

Note : inorder to represent a blank line i have used 'BlankLine'.
My doubt is how 1 blank line in begining and 1 blank line in between the lines are preserved. Also all blank lines at the end are removed.

Can anyone please explain this.?


Thank You

Viewing all articles
Browse latest Browse all 16232

Trending Articles