aflat362
asked on
Script to change CR LF to LF -- 0D 0A to 0A
I'm trying to get a script written to change the carrige return linefeed characters to linefeed characters
I have a file where all lines end with Hex 0D 0A I want them to end with 0A
I tried using sed to do a search and replace - something like this:
sed -e 's/\x0D/whatever/' test.txt > test.new
Search for 0d and replace with "whatever"
I just wanted to get this working first - Anyway - sed runs without error but apparetnly can't find any 0D in my file
even though I know the hex character exists.
Thanks
I have a file where all lines end with Hex 0D 0A I want them to end with 0A
I tried using sed to do a search and replace - something like this:
sed -e 's/\x0D/whatever/' test.txt > test.new
Search for 0d and replace with "whatever"
I just wanted to get this working first - Anyway - sed runs without error but apparetnly can't find any 0D in my file
even though I know the hex character exists.
Thanks
ASKER
I don't have either of those executables . . .
[x67167] dbimg1:/home/x67167) dos2unix
ksh: dos2unix: not found.
[x67167] dbimg1:/home/x67167) recode
ksh: recode: not found.
[x67167] dbimg1:/home/x67167) dos2unix
ksh: dos2unix: not found.
[x67167] dbimg1:/home/x67167) recode
ksh: recode: not found.
ASKER
I'm running AIX 5.2 ml 4
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hmm.
I don't have perl installed.
I'd like to get this working with the tools I have:
shell (korn, bourne or C)
awk
sed
Thanks for the posts.
I don't have perl installed.
I'd like to get this working with the tools I have:
shell (korn, bourne or C)
awk
sed
Thanks for the posts.
ASKER
nevermind. I do have perl.
This may work for me.
cat test.txt | perl -ne 'y/\r//d; print' > test.new
Can you explain what the y/\r//d; part of this command is doing?
or point me to a reference?
Thanks
This may work for me.
cat test.txt | perl -ne 'y/\r//d; print' > test.new
Can you explain what the y/\r//d; part of this command is doing?
or point me to a reference?
Thanks
cat file.txt | sed -e 's/\r//'
#but please verify that it in fact removes the char...
#but please verify that it in fact removes the char...
Bots, sed and perl s/// or y///d searches for given character, then rplaces with replaement char(or removes if no replacement found
y/ab/c/d # changes each occurance of 'a' to 'c' and remoes any 'c'.
y/ab/c/d # changes each occurance of 'a' to 'c' and remoes any 'c'.
removes any 'b' character - dorry for mistake above.
ASKER
Ok, so for this example it searches for \r which must equate to 0D 0A and replaces it with what? null?
what's up with the "d"?
cat test.txt | perl -ne 'y/\r//d; print' > test.new
Thanks
what's up with the "d"?
cat test.txt | perl -ne 'y/\r//d; print' > test.new
Thanks
in fact - not really. It searched for any \r and removes. 'd' stands for delete found but not replaced characters.
For more please see: man perlop, operation 'tr' or 'y'
For more please see: man perlop, operation 'tr' or 'y'
ASKER
Thanks!
dos2unix test.txt test.new
recode ibmpc..lat1 text.txt > test.new