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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert CR/LF pair into LF (Binary files)

Status
Not open for further replies.

motoslide

MIS
Oct 30, 2002
764
US
I have a set of files where were FTP'd without using BINARY. The results might be trash, but I'd like to try recovery by locating all 0d0a pairs and replace those with just 0a.

I've tried this command:
tr '\015\012' '\012' <infile >outfile
That replaces 0d0a with 0a0a.

I tried:
tr -d '\015\012' '\012' <infile >outfile
That removes ALL instances of 0d AND 0a.

The "dtox" or "dos2unix" commands won't fly well on binary files.

Any help is appreaciated, as always!

"Proof that there is intelligent life in Oregon. Well, Life anyway.
 
I think you should have used:

tr -d '\015' < infile > outfile.
 
I almost suggested that, but that strips all \015's, not just those that occur as \015\010 pairs.
 
Thanks, but there are isolated "0d" bytes which must remain.

I think I was able to do what I wanted in PERL. The first couple of files appear to be "salvaged", but I suspect that's being overly optimistic.

Here is the PERL line:

$ perl -p -e 's/(\r\n)/\n/g' badfile > goodfile



"Proof that there is intelligent life in Oregon. Well, Life anyway.
 
Check for the programs dos2unix and unix2dos available with many flavours of *nix (it's on RedHat ES4 for example). Usage is
Code:
dos2unix < file_with_cr > file_without_cr

On the internet no one knows you're a dog

Columb Healy
 
I had already tried "dtox" (SCO's version of dos2unix). The problem is that my file also has CNTL-Z characters (hex "1a"), and dtox stopped processing the file at that character. The PERL thing seems to have resolved the problem.

"Proof that there is intelligent life in Oregon. Well, Life anyway.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top