At the Linux/Unix command line, I want to turn this:

A
B
C
A
B
C
.
.
.

into this:

A,B,C
A,B,C
...

Is there a simple built-in command to do this, or does this require diving into Awk, Perl, etc.?

link|improve this question
feedback

2 Answers

up vote 5 down vote accepted

Don't know such built-in. Using Bash you can:

while read a && read b && read c ; do echo $a,$b,$c ; done < file
link|improve this answer
feedback

That is horrible, surely something like

tr \\n ' '

would do the same thing?

So for e.g. to join lines of the file *file_lines* use

cat file_lines | tr \\n ' '
link|improve this answer
2  
He didn't want all of it on a single line, it seems. – l0b0 Feb 17 at 10:42
Exactly. Referencing the problem statement, this would produce a single line with everything on it (A B C A B C A B C A B C A B C ...) which is not what was requested. – Alan Krueger Feb 17 at 17:08
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.