shell script/command for converting columns/table onto a single line
Hi all,
I'm after a command, or a sequence of commands that can help me convert values in a table (columns and rows) to values on a single line. The number of columns in the input file is always the same but the number of rows can vary. eg The table might look like the following: A B C D E F G H I J K L I need the information to be output onto a single line that looks like the following. A B C D E F G H I J K L Any help would be greatly appreciated. |
"echo" is doing this job.
Code:
$ a="a b c |
that is fu@King brilliant.
thank you very much |
Quote:
Code:
tr -d '\n ' < file_with_table |
I ended up using the echo command in my script. It took two lines instead of one but I prefer the simplicity. I did the following.
Quote:
|
You probably should be using 'cat' instead of 'more'.
|
file=$(<yourfile)
|
The "cat file | tr '\n' ' ' >newfile" example will add a space after the last item if the last lines ends with a newline as is apt to be the case.
The 2nd post isn't taking the input from a file. The "file=$(<yourfile); echo $file < newfile" example works perfectly. I think the 2nd post showing the difference between $a and "$a" and the later one completed it by entering the file into a variable: a=$(<temp) ~> echo "$a" >newfile A B C D E F G H I K L M N O P ~> echo $a >newfile A B C D E F G H I K L M N O P |
Using an intermediary variable may be unnecessary:
Code:
$ cat file |
if it's not too large
xargs < file will do it too, of course you need to be careful if the file has meta-characters in it |
All times are GMT -5. The time now is 05:13 PM. |