bash to print words/lines horizontally
Hi All,
I have a test file with below entries Code:
$ cat /tmp/test Code:
RedHat Cent Fedora Suse Ubuntu |
Using tr:
Code:
cat infile | tr "\n" " " Code:
awk 'BEGIN{ ORS=" " }{ print }' infile |
pure bash:
Code:
foo="$(<infile)" Code:
<infile mapfile -t array |
Thank you both, worked as expected. But druuna both of your commands output are in the same line where will be "user@hostname:~$", it is okay I can cut and paste the output.
Once again thanks a lot druuna and millgates. |
Quote:
Code:
cat infile | tr "\n" " " && echo Code:
awk 'BEGIN{ ORS=" " }{ print }END{ print "\n"}' infile Code:
awk 'BEGIN{ ORS=" " }{ print }' infile && echo |
Adding to druuna post.
Quote:
|
Code:
paste -sd' ' file |
Code:
echo $(<file) |
Thank you all for giving lot of ways to achieve this.
Code:
@millgates Once again thank you all. |
One more way: :)
Code:
~$ for word in $(cat /tmp/test); do echo -n "$word "; done; echo |
Quote:
Code:
~$ while read word; do echo -n "$word"; done < /tmp/test; echo |
Quote:
@Everyone: How can I read a file (data stream, variable) line-by-line (and/or field-by-field)? (Link) And Why you don't read lines with "for" (Link) |
Code:
xargs echo < file |
All times are GMT -5. The time now is 06:47 PM. |