Results 1 to 6 of 6
I know virtually no unix BUT
I want to remove line feed \n from a file but only when NOT preceded by carriage return \r - this is a file ...
- 09-16-2011 #1Just Joined!
- Join Date
- Sep 2011
- Posts
- 3
Command to remove \n from Windows file but preserve \r \n
I know virtually no unix BUT
I want to remove line feed \n from a file but only when NOT preceded by carriage return \r - this is a file copied from windows. Our Oracle data load script needs to read the next record after \r \n but ignore \n embedded in text
Steve EdmeadesLast edited by oz; 09-16-2011 at 07:20 PM. Reason: only your name is permitted in manual user signatures
- 09-18-2011 #2
This is probably to ridiculously misunderstand the problem but:
cat just sends the four lines below through the pipe. The first sed removes the \n's and the second looks for \r and adds an \n to it.Code:$ cat|sed 's/\\n//g'|sed 's/\\r/\\r\\n/g' The wholesome bread\r\n Of Mrs. Brag\n Fell to the ground\r\n As if twere dead\n The wholesome bread\r\n Of Mrs. Brag Fell to the ground\r\n As if twere dead
Discovered that grep \\\\ looks for \ - it's true.
Last edited by lugoteehalt; 09-18-2011 at 06:00 AM.
- 09-19-2011 #3Just Joined!
- Join Date
- Sep 2011
- Posts
- 3
Thanks lugoteehalt, appreciate your help - I think you have grasped the issue. How do I do that operation on files - ie Take MYfile1 process it in the way you say and end up with a cleaned up file MYfile2. This would be a line I could include in a shell script.
Thanks again
Steve Edmeades - Cancer Research UK
- 09-19-2011 #4
sed 's/\\n//g' < MYfile1 | sed 's/\\r/\\r\\n/g' > MYfile2
It has to actually have the characters \r and \n, you know - as written to work.
It won't do anything to:
The chief defect
Of Henry King
It has to be:
The chief defect\n and stuff like that.
Seems to work. You'd run that with:Code:#! /bin/bash # Remove \n's but not \r\n's. MYfile1=$1 sed 's/\\n//g' < "$MYfile1" | sed 's/\\r/\\r\\n/g' > MYfile2
$ bash progName.sh /path/to/MYfile1 or something.Last edited by lugoteehalt; 09-19-2011 at 12:24 PM.
- 09-19-2011 #5Just Joined!
- Join Date
- Sep 2011
- Posts
- 3
Thanks for giving me some more of your time on this,
that did not quite work in my scenario, but after playing around a bit this did seem to do the trick:-
cat file1 | tr -d '\n' | sed 's/\r/\r\n/g' > file2
- 09-19-2011 #6
You sure?
tr's nice, had never heard of it.Code:lugo@debian:~/Videos/Medicine$ echo "\r"|sed 's/\r/\r\n/g' \r lugo@debian:~/Videos/Medicine$ echo "\r"|sed 's/\\r/\\r\\n/g' \r\n lugo@debian:~/Videos/Medicine$


Reply With Quote
