in reply to couple of file content manipulation questions

The output of df is fixed length fields. You can use pack/unpack to get at the data. Read the pack tutorial on how this works. Basically, you calculate the field widths and feed them to pack which splits up the string for you. Then all your loop needs to do is recognize header and footer lines and handle them as special cases. Everything else is simply unpack()ed. No messy regexes.

Based on your data, I would do something like:

  1. read line of dashes
  2. read header line and parse with regex(unpack could work here)
  3. read lines till I saw /^Filesystem/
  4. read lines and send through unpack until a blank line
  5. process footer lines with regex or unpack
  6. read next line of dashes and back to the top

I notice that your data may be coming from different sources with different field widths. This may just be the cutting and pasting. But if it is so, you can actually use the header line of your data(from each machine) with index() to calculate the field widths and feed those to pack.

HTH

  • Comment on Re: couple of file content manipulation questions