Hi All,
I want to remove carriage return in a file using some unix command without writing a script
my file is as follows
abc1 abc2 abc3 abc4
abc5 bac6
abc1 abc2 abc3 abc4
abc5 bac6
I want the output as follows:
abc1 abc2 abc3 abc4 abc5 bac6
abc1 abc2 abc3 abc4 abc5 bac6
,
Please tell me how to remove the spaces withut loosing the message
Try:
perl -pe 's/\n/ / if $.%2' file
based on the input given ..
$ paste -d' ' - - < infile
Try
code:
cat filename | xargs -n 2
@tarun , you get a useless use of cat award ..
I assume, with -n
option we cannot achieve the expected output.
Instead we can to do in this way with xargs
$ xargs -L 2 < infile
abc1 abc2 abc3 abc4 abc5 bac6
abc1 abc2 abc3 abc4 abc5 bac6
methyl
January 4, 2012, 7:18am
6
Can be done with "-n"
cat filename | xargs -n 6
abc1 abc2 abc3 abc4 abc5 bac6
abc1 abc2 abc3 abc4 abc5 bac6
Incase the second line has 3 values then it will fail .. It will not bind 2 lines as a single line ..
$ cat infile
abc1 abc2 abc3 abc4
abc5 bac6 abc1
abc1 abc2 abc3 abc4
abc5 bac6
$
$ xargs -n 6 < infile
abc1 abc2 abc3 abc4 abc5 bac6
abc1 abc1 abc2 abc3 abc4 abc5
bac6
$
$ xargs -L 2 < infile
abc1 abc2 abc3 abc4 abc5 bac6 abc1
abc1 abc2 abc3 abc4 abc5 bac6
$
@ Jayan, agreed with you.
@ Manish, with sed you can try below
sed -n '
{
N
s/\n//;p;
}
' filename