![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
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 |
|
#3
|
|||
|
|||
|
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
|
||||
|
||||
|
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
|
|||
|
|||
|
DOS to Unix: sed s/.$//g file > outfile
Unix to DOS: sed s/$/x0d/g file > outfile |
|
#6
|
|||
|
|||
|
Quote:
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. |
|
#7
|
||||
|
||||
|
Oops...
Good catch Vishnu |
||||
| Google The UNIX and Linux Forums |