Give this a try:
Code:
sed -i ':loop;/^M/!{N;bloop};s/\n/ /g' infile
The ^M is special and can be created like this: type
ctrl-v then
ctrl-m
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
0000000 o n e t w o t h r e e \r \n
0000020 f o u r f i v e s i x \r \n
0000040 s e v e n \n e i g h t \n n i n e
0000060 \r \n t e n e l e v e n t w
0000100 e l v e \r \n
0000107
After:
Code:
0000000 o n e t w o t h r e e \r \n
0000020 f o u r f i v e s i x \r \n
0000040 s e v e n e i g h t n i n e
0000060 \r \n t e n e l e v e n t w
0000100 e l v e \r \n
0000107
The
\r \n sequence represents the dos newline (the ^M). A single
\n is a linux newline.