How to remove blank lines in a file and save the file with same name?

I have a text file which has blank lines. I want them to be removed before upload it to DB using SQL *Loader. Below is the command line, i use to remove blank lines.

sed '/^ *$/d' /loc/test.txt

If i use the below command to replace the file after removing the blank lines, it replace the existing file with a blank file.

sed '/^ *$/d' /loc/test.txt > /loc/test.txt

Use -i option ..

$ sed -i '/^$/d' infile
1 Like

You dont need to delete blank lines before using sqlldr. In the control file, use...

MISSING FIELD VALUES ARE NULL
REJECT ROWS WITH ALL NULL FIELDS

I am unable to load the text file to DB after including

MISSING FIELD VALUES ARE NULL
REJECT ROWS WITH ALL NULL FIELDS

in control file. I guess this will apply for external table only.

---------- Post updated at 02:06 AM ---------- Previous update was at 02:01 AM ----------

It works well with -i option

go in to insertion mode by pressing I...now to remove a row press dd....this will completely remove the row and to save the fileuse the command
:wq to quit and save the file
:w to save the file but still be inside the vi editor

I am not doing this manually. I need a shell command which just do this.

This will remove all blank lines (lines containing spaces, tabs, \n)

perl -i -ne '(!/^\s+$/)&&print' inputfile