Operating System - HP-UX
1830052 Members
2200 Online
109998 Solutions
New Discussion

How do I remove cr's from a file ??

 
SOLVED
Go to solution
Lee Oliver
Advisor

How do I remove cr's from a file ??

Hello all,

I wondered if you could help.....

I need to remove cr's (carriage returns) from a file.

many thanks
Lee
i am what i am
11 REPLIES 11
KapilRaj
Honored Contributor

Re: How do I remove cr's from a file ??

cat filename |tr "\n" " "

Cheers

Kaps
Nothing is impossible
john korterman
Honored Contributor
Solution

Re: How do I remove cr's from a file ??

Hi,
try this:
# tr -d "\012" <./infile > ./outfile

regards,
John K.
it would be nice if you always got a second chance
Lee Oliver
Advisor

Re: How do I remove cr's from a file ??

Thanks but this doesn't seem to work.

Cheers
Lee
i am what i am
H.Merijn Brand (procura
Honored Contributor

Re: How do I remove cr's from a file ??

# perl -pe 's/\r//g' yourfile > newfile

Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Lee Oliver
Advisor

Re: How do I remove cr's from a file ??

Thanks John, That worked a treat. 10/10.

Cheers
Lee
i am what i am
John Poff
Honored Contributor

Re: How do I remove cr's from a file ??

Hi,

You can also use the 'dos2ux' command.

JP
Massimo Bianchi
Honored Contributor

Re: How do I remove cr's from a file ??

check the commands


dos2ux

and

ux2dos


they exists just for that :)

Massimo

john korterman
Honored Contributor

Re: How do I remove cr's from a file ??

Hi again,
well, I guess that your CRs are not byte 10. Please create the file myfile with only two lines holding this text:

line1
line2

and post the output of this command:
# head myfile| od -x

it should look like this:
0000000 6c69 6e65 310a 6c69 6e65 320a
0000014


regards,
John K.

it would be nice if you always got a second chance
Michael Schulte zur Sur
Honored Contributor

Re: How do I remove cr's from a file ??

Hi,

you can also use ftp to transfer the binary to your computer and then ascii back.

greetings,

Michael
Michael Schulte zur Sur
Honored Contributor

Re: How do I remove cr's from a file ??

Hi,

Johns doesnt work. It deletes the newlines. To delete carriage returns, you would have to use:

tr -d "\015" <./infile > ./outfile

greetings,

Michael
Rory R Hammond
Trusted Contributor

Re: How do I remove cr's from a file ??

You alread have lots of answers

\n is a line feed
\012 is also line feed

\r is carriage return
\015 is also carriage return

so "cat |filename |tr -d "\r" "" > newfile"

will remove carriage returns.

If the data file you have was a binary transfer of text text file from an Old Mac you would need to translate
the \r to \n becuase they only had \r

so "cat |filename |tr "\r" "\n" > newfile"


"strings filename > newfile"
will also work

When ftp'ing textfiles between different platforms (windows,mac and unix). set the file type to ascii and your \cr\lf,\cr,\lf problems will be less
Rory
There are a 100 ways to do things and 97 of them are right