Tech Support > Operating Systems > Linux / Variants > Need some help in fixing a file
Need some help in fixing a file
Posted by Chris F.A. Johnson on January 26th, 2004


On Mon, 26 Jan 2004 at 03:03 GMT, Madhusudan Singh wrote:
^M is a CR.

Are you saying there are no LF (a.k.a. newline, linefeed, ^J, 0xA)
characters?

The standard end-of-line on *nix systems is LF; on Mac it's CR; on
DOS/Windows it's CR/LF.

To convert all the CRs to LFs:

tr "\r" "\n" < FILE > NEWFILE

To delete all CRs:

tr -d "\r" < FILE > NEWFILE ## see also the dos2unix command

To convert CRs to CR/LFs:

sed 's/^M/^M\
/g' FILE > NEWFILE

(Those ^Ms are actual CRs; on the command line, type ^V^M, or ^Q^M
in emacs.)

--
Chris F.A. Johnson http://cfaj.freeshell.org
================================================== =================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License


Similar Posts