I am pasting my output of the shell script

for i in `cat disk.txt`; do
    echo Server:$i
    ssh -q -i ~/production_private_key.pem $i "df -h --output=source,size,used,avail,pcent| grep -v tmp"


enter image description here

I need to print the above output to different columns like as below.

Server IP |  File System | Total Size | Used Space | Available Space | Percentage

Can someone help here?

  • 1
    Welcome to the site. Please, don't post screenshots of console output, it is often difficult to read, and and obstacle for contributors trying to help - in particular when serving as sample input, where contributors would need to type-copy the output for testing their suggested solutions. Also, please show us what you already tried and where you ran into problems.
    – AdminBee
    Commented May 25, 2020 at 7:28

1 Answer 1


Add the IP for each line using xargs:

echo 'Server IP |  File System | Total Size | Used Space | Available Space | Percentage'
for i in ...; do
    ssh -q -i ~/production_private_key.pem $i "df -h --output=source,size,used,avail,pcent \
    | tail -n+2 \
    | grep -v tmp" \
    | xargs -I{} printf '%s %s\n' "$i" {}

Replacing blank with | should be easy

  • Added some modification with above script and it's worked. Thanks
    – Afsal K R
    Commented May 25, 2020 at 10:34
  • This is my script output1=/tmp/disk-usage.out echo "------------------------------------------------------" echo "Server Filesystem Size Used Avail Use% " echo "------------------------------------------------------" for server in more /home/ec2-user/disk.txt do output=ssh -q -i ~/production_private_key.pem $server "df -h --output=source,size,used,avail,pcent | grep -v tmp | tail -n +2" echo "$server $output" >> $output1 done cat $output1 | column -t
    – Afsal K R
    Commented May 25, 2020 at 10:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .