Avoid carriage return until ^M is found (CentOS 6, bash 4.1)
Hi everyone,
I have the following contents in a text file (as seen when viewed using vim): Code:
one two three ^M How can I obtain the following result? Code:
one two three ^M Thanks in advance. |
Give this a try:
Code:
sed -i ':loop;/^M/!{N;bloop};s/\n/ /g' infile As a side effect the ^M's are not longer visible when opened in vi. This because the file is now a dos file and not a mixed dos/linux file. Below a dump of the input file. Before: Code:
$ od -c infile Code:
0000000 o n e t w o t h r e e \r \n |
You could also try awk:
Code:
awk -F"[ \n]" 'BEGIN{ORS=RS="\r\n"}$1=$1' file |
All times are GMT -5. The time now is 05:41 PM. |