How to join output of two command in same line?

Hi

I am trying to figureout how to join output of two command in unix in the same line.

for e.g.

$ankit : df -h | egrep -w /home | awk '{print -n $1 "\t" $5}' ;stat --format=%a /home

Output:

0148G /home
775

I want this output as...

0148G /home 775

Please let me know if you need more info from my side.
Thank you for help.

Try this:

df -h | awk -v A=$(stat --format=%a /app) '/[^ \t]\/home/" {print $1,$5,A }' OFS='\t'
1 Like

Alternatively, pipe your output into paste .

Regards,
Alister

1 Like

Hi Sorry...
actually there was an typo in my post; there is not /app directory but only home directory so your command is also not working my PC....

$ankit : df -h | egrep -w /home | awk '{print -n $1 "\t" $5}' ;stat --format=%a /home
Output:
0148G /home
775

I want this output as...
0148G /home 775
--------------------------------------------------------------------------------
I am able to make this command and its working on terminal but I want to use this command in perl script and want to run in multiple server....

The bllow command line also look ugly and I am sure there is some better way to do this......

 
 
 df -h | egrep -w '/home' | awk '{print $5 "\t" $1 }' | tr -d '\n' ; echo -n "  " ;stat --format=%a  '/home'| tr -d "\n" ; echo -n "  " ;stat --format=%U '/home' | tr -d "\n" ;  echo -n "  " ;stat --format=%G '/home'

Output

/home    148G  775  own1  frnd1

I am getting output at terminal but the it won't work in my perlscript

my $file = $ARGV[0];
open SLIST, $file or die $!;
my @allserver = (<SLIST>);
foreach my $server (@allserver){
        chomp($server);
        `ssh $server   "df -h | egrep -w '/home' | awk '{print \$5 '\t' \$1 }' | tr -d "\n" ; echo -n '  ' ;stat --format=%a  '/home'| tr -d '\n' ; echo -n '  ' ;stat --format=%U '/home' | tr -d '\n' ;  echo -n '  ' ;stat --format=%G '/home' " > $server`;

Perl script not working here

how about something like this:

printf "%s\t" \
    $(df | awk '/\/home/ { print $1,$5}') \
    $(for T in a U G ; do stat --format=%$T /home ; done)

You would call it from perlscript like this:

my $file = $ARGV[0];
open SLIST, $file or die $!;
my @allserver = (<SLIST>);
foreach my $server (@allserver){
        chomp($server);
        `ssh $server "printf '%s\t' \\\$(df | awk '/\\/home/ { print \\\$1,\\\$5}') \\\$(for T in a U G ; do stat --format=%\\\$T /home ; done)" > $server`;
}
1 Like

Should your stat provide file system date as well, try:

echo -n $disk  $(($(stat -f -c"%s * %a / 1024" $disk) )) " "; stat -c"%a %U %G" $disk
1 Like

HI....
Thanks a lot for your help and code, its working fine. Still, I am unable to understand the use of 3 backspace (escape character)

One lot of backslashes is stripped by perl when generating the system call:

ssh kotak-pc "printf '%s<tab>' \$(df | awk '/\/home/ { print \$1,\$5}') \$(for T in a U G ; do stat --format=%\$T /home ; done)" > kotak-pc

The shell then removes another set of backslashes when the ssh command line arguments are processed sending the following thru to the kotak-pc server:

printf '%s<tab>' $(df | awk '/\/home/ { print $1,$5}') $(for T in a U G ; do stat --format=%$T /home ; done)
1 Like