The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 10-29-2002
Registered User
 

Join Date: Aug 2002
Location: Marlboro, MA
Posts: 114
Can we use sed for this?

Yesterday I suggested this as a reply to a post, but when I sat to do it myself I was having problems!

I want to convert a UNIX text file to DOS and vice versa.

I mean I want to convert a single LF to CRLF and vice versa.

Can I do it with sed? If not, how else can I do it?

LF - line feed - octal 012
CR - carriage return - octal 015

I know this is not much of practical use (as we can do these conversions using ascii mode in ftp ) - just curious.

Cheers!
Vishnu.
Reply With Quote
Forum Sponsor
  #2  
Old 10-29-2002
Kelam_Magnus's Avatar
Registered User
 

Join Date: Aug 2001
Location: DFW McKinney, TX,
Posts: 1,069
just use mail or ftp with ascii

I am not sure what you mean. A UNIX text file IS a plain text doc in WINDOWS. If you want to format it, wait until you open it with MS WORD and format then.

I am sure there is a way to format it beforehand, but it slips my mind just now.

However, you can just email the file to your PC from the unix box. or use ftp with the ascii setting and you should have NO problems!

mailx -s "myfile" me@myhost.com < myfile.txt


Should be that easy!

__________________
My brain is your brain
Reply With Quote
  #3  
Old 10-29-2002
Registered User
 

Join Date: Jun 2002
Location: Amsterdam (Netherlands)
Posts: 142
See also

Removing the ^M character in VI


And
there was a strange character(^M) been added automatically in UNIX


Somewhere on this board you can find the sed sequense to.
Sorry i did not find it
Reply With Quote
  #4  
Old 10-29-2002
LivinFree's Avatar
Goober Extraordinaire
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
Kelam, if you create a text file in Windows with Wordpad, or (guffaw) DOS EDIT, instead of having a "\n" (newline) at the end of each line, you will get a "\n\r" (newline, carriage return).

That's what the dos2unix/unix2dos utilities mainly correct.

In HP-UX, they're called ux2dos and dos2ux.
Reply With Quote
  #5  
Old 10-31-2002
Registered User
 

Join Date: Oct 2002
Posts: 17
DOS to Unix: sed s/.$//g file > outfile
Unix to DOS: sed s/$/x0d/g file > outfile
Reply With Quote
  #6  
Old 11-01-2002
Registered User
 

Join Date: Aug 2002
Location: Marlboro, MA
Posts: 114
Quote:
you will get a "\n\r" (newline, carriage return).
Not that how DOS delimits its records (or lines) is sacrosanct...

but the DOS delimiter is "\r\n" or "\o015\o012" or CRLF

Cheers!
Vishnu.

Last edited by Vishnu; 11-04-2002 at 04:52 PM.
Reply With Quote
  #7  
Old 11-02-2002
LivinFree's Avatar
Goober Extraordinaire
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
Oops...
Good catch Vishnu
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:51 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0