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! :slight_smile:

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.

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!

:smiley:

And

Somewhere on this board you can find the sed sequense to.
Sorry i did not find it

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.

DOS to Unix: sed s/.$//g file > outfile
Unix to DOS: sed s/$/x0d/g file > outfile

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.

Oops...
Good catch Vishnu :slight_smile: