Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert Unix-Dos file to Dos file!

Status
Not open for further replies.

shaokat

Technical User
Oct 8, 2002
11
0
0
IN
I have a file which has been created using two different systems and contains both the Unix and Dos file type.

ie. line ending with \r in some cases and \r\n in the rest.

How do I effectively convert this file into a DOS file and or Unix file?

This is what I have am trying, but not able to use any of sed, tr and awk scripts:

1. Remove '\n' using tr -d '\n'
2. Replace \r' with '\r\n'

I am not finding the sed option to replace '\r' with '\r\n'.

Any help??

Thanks,
 
Which OS? If supported (Solaris for example), dos2unix and unix2dos should do what you require. There are also variants for other OS's.
 
thread822-937029

might help as well...
 
Ultraedit will do this with 2 clicks of a mouse, and give you a great text editor at the same time!
 
Solaris:
unix2dos, dos2unix

AIX:
dosread, doswrite

tr -d '\r'

sed 's/^M//g' file > newfile #where ^M is ctrl-v/ctrl-m

ftp would also work with the binary and ascii subcommands.
 
unix2dos emulation :
awk '!/\r$/{printf "%s\r\n",$0;next}{print}' unixfile > dosfile
dos2unix emulation :
tr -d '\r' <dosfile >unixfile

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top