I would like to convert my one colum of many rows into one line:
example :
1
1
1
1
1
2
2
2
3
3
4
and I want :
11111222334
any suggestion please?
paste:
$ paste -s -d "" file
11111222334
squeeze all lines together with no delimiter.
or these solutions that delete even the trailing newline
perl -pe chomp file
awk -v ORS="" 1 file
You could delete all newline characters with tr
:
tr -d \\n <infile
Note there's no trailing newline character in the output so, if that's needed (e.g. to redirect to another file):
{ tr -d \\n <infile; printf \\n; } >outfile
If, instead, you need the fields separated by a space you could run:
row=$(tr \\n \ <infile)
printf %s\\n "${row%?}" >outfile
though paste
really shines here...
You can also try echoing the command and sendig the output to a new file.
$ echo $(cat file) >> rows.txt
To prevent whitespaces between each line you can use sed in the same line
$ echo $(cat file) | sed 's/ //g' >> rows.txt
\[*?
. It'll also strip off all whitespace, which may or may not (probably not) have been desired.
Sep 30, 2015 at 22:54