I have a function in bash that prints a bunch of lines in stdout. I want to combine them in one line with some separator between them.
Before:
one two three
After:
one:two:three
What is an easy way to do this?
Use paste
paste
$ echo -e 'one\ntwo\nthree' | paste -s -d':' one:two:three
This might work for you:
paste -sd':' file
:
cat file | tr -s "\n" ":"
@glennJackman
awk '{printf("%s%s", sep, $0); sep=":"} END {print ""}' file
, bash
while read line ; do printf "%s:" $line ; done < file | sed s'/:$//'
,
bash -:
echo $'one\n2 and 3\nfour' | { mapfile -t lines; IFS=:; echo "${lines[*]}"; }
one:2 and 3:four
{} , , , . .
{}
http://www.gnu.org/software/bash/manual/bashref.html#index-mapfile-140
input.txt
Perl : dummy.pl
@a = `cat /home/Input.txt`; foreach my $x (@a) { chomp($x); push(@array,"$x"); } chomp(@array); print "@array";
script :
$> perl dummy.pl | sed 's //: / g'> Output.txt
output.txt
one two Three