Extracting some part of Perl's Expect Buffer

Hi,

I am capturing command's output on remote host using Expect. The problem is that the command line arguments also getting print with the output in file and also need to print last two relevant columns (percentage used and its mounted point).

The output of $exp->before() buffer is :

df
Filesystem      1K-blocks     Used Available Use%     Mounted on
devtmpfs         4063064        8   4063056    1%            /dev
tmpfs            4074272        0   4074272       0%             /dev/shm
tmpfs            4074272   141132   3933140     4%             /run
tmpfs            4074272        0   4074272        0%           /sys/fs/cgroup
/dev/sda1       20510332 15487436   3974372  80%       /
/dev/sdb1       10189112   964776   8700100    10%        /var/log
tmpfs             814856        0    814856            0%           /run/user/107
tmpfs             814856        0    814856          0%             /run/user/0

I need following output. Deleted first line (df) and only last two columns interchanged:

Mounted on     Use%  
/dev                       1%
/dev/shm             0%
/run                      4%
/sys/fs/cgroup   0%
/ 	                     80%
/var/log              10%
/run/user/107    0%
/run/user/0       0%

Thanks

Welcome suneet17,

I have a few to questions pose in response first:-

  • Is this homework/assignment? There are specific forums for these.
  • What have you tried so far? Please paste this in CODE tags.
  • What output/errors do you get?
  • What OS and version are you using?
  • What are your preferred tools you are calling this in with? (C, shell, perl, awk, etc.)
  • What logical process have you considered? (to help steer us to follow what you are trying to achieve)

Most importantly, What have you tried so far?

There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.
Is there a reason not to just use something like ssh $user@$server df > $local_output_file ?

We're all here to learn and getting the relevant information will help us all.

Thanks, in advance,
Robin