Smart questions
Smart answers
Smart people
Join Tek-Tips Forums
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

curious01 (TechnicalUser) (OP)
26 Sep 06 5:28
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
Annihilannic (MIS)
26 Sep 06 5:41
Those lines aren't empty, they have spaces on them.

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

Annihilannic.

PHV (MIS)
26 Sep 06 5:49
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

curious01 (TechnicalUser) (OP)
26 Sep 06 5:52
Hi Annihannic
Thanks for replying.
I tried your command but it did not change anything in my file either. Any alternatives :)

curious1
curious01 (TechnicalUser) (OP)
26 Sep 06 5:55
Hi PHV
Your suggestions did not work either. Is it because I am using nawk on Sun OS?

curious1
PHV (MIS)
26 Sep 06 5:59
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

p5wizard (IS/IT--Management)
26 Sep 06 6:18
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

Annihilannic (MIS)
26 Sep 06 7:14
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.

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

If you knew that already, ignore me.  smile

Annihilannic.

curious01 (TechnicalUser) (OP)
27 Sep 06 5:27
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

Annihilannic (MIS)
27 Sep 06 5:36
Try

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

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

So it should look like this:

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

Annihilannic.

p5wizard (IS/IT--Management)
27 Sep 06 5:42
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

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close