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 and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-29-2002
Vishnu Vishnu is offline
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.
  #2 (permalink)  
Old 10-29-2002
Kelam_Magnus's Avatar
Kelam_Magnus Kelam_Magnus is offline Forum Advisor  
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!

  #3 (permalink)  
Old 10-29-2002
janr janr is offline
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
  #4 (permalink)  
Old 10-29-2002
LivinFree's Avatar
LivinFree LivinFree is offline Forum Advisor  
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.
  #5 (permalink)  
Old 10-31-2002
itsupplies itsupplies is offline
Registered User
  
 

Join Date: Oct 2002
Posts: 23
DOS to Unix: sed s/.$//g file > outfile
Unix to DOS: sed s/$/x0d/g file > outfile
  #6 (permalink)  
Old 11-02-2002
Vishnu Vishnu is offline
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 07:52 PM..
  #7 (permalink)  
Old 11-02-2002
LivinFree's Avatar
LivinFree LivinFree is offline Forum Advisor  
Goober Extraordinaire
  
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
Oops...
Good catch Vishnu
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:32 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0