Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove empty lines

Status
Not open for further replies.

curious01

Technical User
Feb 22, 2006
13
SG
Hi
I am trying to remove empty lines in my file using:
sed '/^$/d' file.txt

However, nothing seems to be removed. Can you help me here please :)

my file looks like this:

3621 PSMD5 NM_005047
23626 NELL2 NM_006159

23633
23643 CAPN2 NM_001748

23661 PIAS4 NM_015897
23684 STMN1 NM_005563

Thanks.

curious1
 
Those lines aren't empty, they have spaces on them.

Try sed '/^ *$/d' file.txt.

Annihilannic.
 
Another way:
awk NF file.txt

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi Annihannic
Thanks for replying.
I tried your command but it did not change anything in my file either. Any alternatives :)

curious1
 
Hi PHV
Your suggestions did not work either. Is it because I am using nawk on Sun OS?

curious1
 
Seems you have some control char in your file, perhaps CR (\r) ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
try an "od -xc" on the same excerpt of the file and post the output back here, perhaps there are only tabs in the file?


HTH,

p5wizard
 
Are you expecting these commands to change the original file? If so, they don't. You will need to redirect the output to a new file.

[tt]sed '/^ *$/d' file.txt > file2.txt[/tt]

If you knew that already, ignore me. :)

Annihilannic.
 
Hi P5wizard,
May I ask what you mean " by adding "od -xc" on the same excerpt of the file and post the output back here"? Sorry, I am still a green beginner in this area :)
Maybe I explain a little about my files.
1)I extracted data from certain columns in Excel tables and saved it as tab-delimited file.
2)After that, I compared 2 files and extract those present in both files.
3)the result I obtained contain many blank/empty lines which I now want to remove using the sed command.

I did not manage to do this with the sed command I mentioned earlier.

Hope you can help.

curious1

 
Try

[tt]sed '/^[ (tab)]*$/d' file.txt > file2.txt[/tt]

However where it says "(tab)" just hit the tab key to insert a tab character.

So it should look like this:

[tt]sed '/^[ ]*$/d' file.txt > file2.txt[/tt]


Annihilannic.
 
you have a piece of your datafile in another file?

od -xc /path/to/piece

you created that excerpt by head or tail?

tail -10 /path/to/file|od -xc

paste the output of the od -xc back here please



HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top