Monday, 20 August 2012

Converting File Formats Using the tr Command


Converting File Formats Using the tr Command
- Simple commands or a script can be used to convert a text file either before or after transfer to make its end of line characters compatible with the destination OS.
- In some versions of *nix, unix2dos and dos2unix can be used
- If the above are not available, the *nix tr command can be used
- To convert a Windows text file so that it is suitable for Unix:
$ tr –d ‘\r’ unixfile.txt
- To convert a file from MAC OS X
$ tr ‘\r’ ‘\n’ unixfile.txt
- To convert from Unix to MAC
$ tr ‘\n’ ‘\r’ macfile.txt


1 comment:

Mark @ unix and linux scripts forum said...

Thanks for this useful article. I have written a similar article on tr command with more examples. Please check it out:
tr command example in unix