How to process Linux "df" command output that wraps lines

Article:HOWTO5953  |  Created: 2006-12-05  |  Updated: 2007-03-05  |  Article URL http://www.symantec.com/docs/HOWTO5953
Article Type
How To



Question

The output of the "df" command in Linux may show long volume names that cause the remainder of the line to wrap to a second line. How can I correctly process wrapped output in Monitor Solution for Linux?

For exmaple, the output of the df command shows in the following:

# df -lk
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/system-home
                       1994684    214964   1779720  11% /home
/dev/mapper/system-opt
                       1048540    107872    940668  11% /opt

What Monitor Solution needs, is to have the "df" command return the results in this format:

$ df -lk
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/system-home  1994684    214964   1779720  11% /home

/dev/mapper/system-opt    1048540    107872    940668  11% /opt

Answer
We recommend using one of the following commands to get the unwrapped output from the "df" command:

  • df -lk | awk '{if(/^[^ ]+$/){remember=$0}else{print remember $0}}'
  • df -Pk

Legacy ID



30752


Article URL http://www.symantec.com/docs/HOWTO5953


Terms of use for this information are found in Legal Notices