I have a list of ids as follows, and I want to convert them to a space separated ids (see output below)
INPUT:-
485238
478892
475507
467737
486413
483571
490005
OUTPUT:-
485238 478892 475507 467737 486413 483571 490005
I have a list of ids as follows, and I want to convert them to a space separated ids (see output below)
INPUT:-
485238
478892
475507
467737
486413
483571
490005
OUTPUT:-
485238 478892 475507 467737 486413 483571 490005
This might work for you (GNU sed):
sed ':a;$!N;s/\n/ /;ta' file
But really this is a job for paste:
paste -sd\ file
N.B. there is a space after the backslash and a space before the file
Using awk
, you can do this:
awk '{printf "%s ",$0}' file
485238 478892 475507 467737 486413 483571 490005
$ more test.txt
485238
478892
475507
467737
486413
483571
490005
$ sed ':a;N;$!ba;s/\n/ /g' test.txt
485238 478892 475507 467737 486413 483571 490005
If you want to send this to a new file:
$ sed ':a;N;$!ba;s/\n/ /g' test.txt > test2.txt
$ more test2.txt
485238 478892 475507 467737 486413 483571 490005