Remove blank line - SED

HI, I have this list of apps like so:

DivX Products.app
DivX Support.app
Uninstall DivX for Mac.app
Build Applet.app
SpringBoard.app
Interface.app
MobileAddressBook.app
MobileSafari.app
MobileSlideShow.app
Preferences.app
Install Flash Player 8 OSX.app
Yap.app
check_afp.app

chess.app

There's that one blank line between "check_afp.app" and "chess.app". How do I remove that blank line? I've already tried "sed '/^$/d'" but it didn't work.

Then the line isn't really blank.

Maybe something like grep -v '[A-Za-z0-9.,:;!?]' (or the equivalent in sed) could help remove it?

That did the trick, thanks :slight_smile:

sed '/^.$/d' file

please test on more data.

Same problem, that space still stays there...

We speculate that it's a DOS carriage return; if so, you might want to convert the whole file to Unix line ending conventions because otherwise, the problem will continue to haunt you whenever you need to match something at end of line, etc. See if dos2unix or your local equivalent would help (search these forums if you can't find a good command installed locally).

So how do I convert the file to UNIX line endings? And if anyone is wondering where I got the weird space from, it was written to the app by an AppleScript script. I told it to write a "return" to the file, following some text. The return should have put a normal line break in there, which it did, but it certainly is an unmanipulatable break.

Mac line endings are Carriage Returns, so just converting CR to LF should make the file Unix-friendly.

tr '\r' '\n' <oldfile >newfile

Again, I urge you to search this site if this does not work directly; this question gets asked and answered every week in one form or another.

To remove DOS-style line breaks:

sed '/^M$//' oldfile > newfile

Notice, that "^M" is a literal line break: in vi press "<CTRL>-<V>", then hit <ENTER> to enter it. You will notice that it is a single character rather than two chars.

To remove lines which contain any number of whitespace (Tabs and or blanks):

sed '/^[<tab><blank>]*$/d' oldfile > newfile

Enter a literal TAB-char (press <TAB>) and a blank, i just wrote it that way to make it easier to read.

Finally, to find out which unprintable character is bothering you: open the file in vi, enter command mode (press ":") and enter "set list". You will see all the unprintable characters as control codes now (tab characters are represented by "^I" for instance, etc.). Only a blank is now printed as blank char. Enter command mode again and use "set nolist" to switch that off again.

I hope this helps.

bakunin

Or you can use cat with the -v or -A options (somewhat depending on your version of cat), or look at a hex dump with od or xxd or hexdump

you can simply remove the blank line by doing
grep . file1 > file2