I want to remove blank lines (empty or with spaces and tabs) from a file from within a perl script.
here's what i tried.

`sed '/^ *\$/d' $file1`;

Does not seem to work for some reason.
Any Help please?

Recommended Answers

All 3 Replies

Take out the space (unless you are looking for lines with just one space)


So, given a file called test.txt, JUST the sed part would be:

sed '/^$/d' test.txt

...or if you just want to do it from the command-line

perl -pi -e "s/^\n//" test.txt

thanks for your replies. $^ matches a blank line(but not a line with spaces). I eventually ended up calling the perl inline from my script. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.