Operating System - HP-UX
1827942 Members
2280 Online
109973 Solutions
New Discussion

join output of two commands on one line

 
SOLVED
Go to solution
ian walker_1
Advisor

join output of two commands on one line

Hi all

I need to join the output of two commands onto a single line and ensure a "," (comma) exists between each field. What is the best way to do this?

e.g. these are the commands I want to output on a single line:

ls -l | awk '{print $1","$3","$4","$5","$9","}'
sum -r | awk '{print $1}'

so my output should be something like:

-rw-rw-rw-,root,sys,65432,filenamea,32508
-rw-rw-rw-,root,sys,65432,filenameb,3233
-rw-rw-rw-,root,sys,65432,filenamec,325221
-rw-rw-rw-,root,sys,65432,filenamed,1292
-rw-rw-rw-,root,sys,65432,filenamee,2838
.............

5 REPLIES 5
RAC_1
Honored Contributor

Re: join output of two commands on one line

ls -l | awk '{print $1","$3","$4","$5","$9","}'; sum -r | awk '{print $1}' | tr "\n" ","
There is no substitute to HARDWORK
RAC_1
Honored Contributor

Re: join output of two commands on one line

echo `ls -l | awk '{print $1","$3","$4","$5","$9","}'` `sum -r | awk '{print $1}'``
There is no substitute to HARDWORK
Simon Hargrave
Honored Contributor
Solution

Re: join output of two commands on one line

It's not technically joining 2 files together, but what I think you want to achieve is this?

for i in $(ls -l | awk '{print $1","$3","$4","$5","$9","}' | grep -v ^total)
do
j=$(sum -r $(echo $i | cut -d, -f5) | cut -d" " -f1)
echo $i$j
done
ian walker_1
Advisor

Re: join output of two commands on one line

last script provided works a treat .. thanks..IW
Gavin Clarke
Trusted Contributor

Re: join output of two commands on one line

You're all too quick for me.

Here is my offering anyway:

for file in `ls`
do
sum=`sum -r $file | awk '{print $1 }'`
list=`ls -l $file |awk '{print $1","$3","$4","$5","$9","}'`
echo $list $sum
done