I am receiving a text files that is fixed length fields and carriage return/newline delimited records (CRLF). Recently one of the text fields started to present with a newline character in the record (LF). This is obviously causing some problems on our unix server.
I would like to simply look for the use of LF in the file and replace it with a single space, but this will obviously interfere with the windows newlines.
I have tried tr and perl but can't quite seem to get it right:
cat badinput.txt | perl -p -e 's/\x0D\x0A/\x0D/' | perl -p -e 's/\0A/ /' | perl -p -e 's/\x0D/\x0D\x0A/' > goodoutput.txt
The idea is to
- replace
CRLFwithCR - replace
LFwith - replace
CRwithCRLF
For some reason I'm not quite getting the CR -> CRLF transformation.
Suggestions?
You can read the whole input with
-0777and then do the substitution:The parameter are:
pwhich outputs the value of$_at the end of each "line"0777which sets the record delimiter to undefPerl Command-line Options