Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

After converting file using **unix2dos** command it is having some empty lines. Please help me. How to handle this?

I tried to delete empty lines as follow, but couldn't work.

$ sed '/^$/d' /tmp/data.txt

Hey following examples also didn't work. Pl help

This is source data before using unix2dos.

ID NAME DATE

1 BALA 09/23/2013

2 KRISHH 09/24/2013

3 billy 09/24/2013

After using unix2dos it is coming as

ID NAME DATE

1 BALA 09/23/2013




2 KRISHH 09/24/2013

3 billy 09/24/2013

first and second record there is an empty line coming up..may be in bewteen data also

Thanks

share|improve this question

migrated from stackoverflow.com Oct 20 '13 at 13:50

This question came from our site for professional and enthusiast programmers.

    
Does sed '/^\s*$/d' work ? –  cnicutar Sep 26 '13 at 10:15
add comment

2 Answers

Under Unix newlines are "\n" and under window they are "\r\n" to convert them you need to replace "\r\n" with "\n", or just get rid of all "\r" if you use notepad++ it can do the conversion for you, and also anything with find and replace should work.

\n = new line

\r = carriage return

Google "Unix line endings" for more information.

share|improve this answer
add comment

As you've mentioned your file has CR-LF line endings. As such, sed '/^$/d wouldn't work.

Try

sed '/^\x0D$/d' inputfile
share|improve this answer
    
hey...sorry it didn't work... –  user2814717 Sep 26 '13 at 10:22
    
Try sed '/^\s*$/d' as commented –  devnull Sep 26 '13 at 10:25
    
sorry..this one also didn't work..why unix2dos command is ging empty lines –  user2814717 Sep 26 '13 at 10:31
    
@user2814717 Post some lines of input before and after issuing unix2dos. Update your question with the information. –  devnull Sep 26 '13 at 11:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.