[PLUG] Translating ^M to \n

Rodney W. Grimes freebsd at gndrsh.dnsmgr.net
Tue Aug 13 00:15:32 UTC 2019


> On Mon, 12 Aug 2019, Paul Heinlein
> 
> > Also, you can use "od -c" to verify the C-style character name tr will 
> > recognize.
> >
> > od -c inffile | less
> 
> Tried this; less showed nothing until the end of the file.

NOTHING?  I think your missing something there, you should of
seen \r's at the end of each line.  If infact there are no \r
in the file then this file is NOT in windows/msdos format.


> Without piping output to less the last character in the file was \r.

And the character before that was?

> 
> Running 'cat <infile> | tr "\r" "\n" > <outfile> left outfile with the same
> ^M as infile. Strange M$ stuff I guess,

*sigh*  you probably do not want to change the CR to a LF, you want to
remove the LF

> If the files are essentially single lines and I use sed with the /g option
> it should replace all \r with \n, but it doesn't.

sed is a line oriented tool, it is doing nasty things your not
thinking about, it is already breaking the line at what it
thinks are line boundaries, as are vi, emacs, etc...

tr is probably the best tool for the job.

> Whew! Thought I had it but that's not the case.

I am starting to think you file may not actually BE windows/dos
line formatted, but something od, your output from od -c should
have lots of \r \n sequences in it.

cat infile | tr -d "\r" >outfile

Removes the CR that windows puts in files that is not used
by unix by translate them to null.  That -d is IMPORTANT!

> Thanks, Paul,
> 
> Rich
> 
> _______________________________________________
> PLUG mailing list
> PLUG at pdxlinux.org
> http://lists.pdxlinux.org/mailman/listinfo/plug
> 

-- 
Rod Grimes                                                 rgrimes at freebsd.org



More information about the PLUG mailing list