java - Setting column width of a command output on AIX -
i'm trying parse df -pg
command's output in java application, print me want.
here output of command:
filesystem gb blocks used available capacity mounted on /dev/hd4 1.00 0.30 0.70 31% / /dev/hd2 3.62 2.65 0.98 74% /usr /dev/hd9var 2.00 0.19 1.81 10% /var /dev/hd3 2.88 1.61 1.27 56% /tmp /dev/hd1 2.00 1.30 0.70 66% /home /proc - - - - /proc /dev/hd10opt 1.00 0.27 0.73 28% /opt /dev/fslv00 2.88 1.25 1.63 44% /tsmfiles /dev/fslv01 2.00 0.84 1.16 43% /opt/ibm/itm /dev/livedump 0.25 0.00 0.25 1% /var/adm/ras/livedump /dev/doonceaix 0.75 0.00 0.75 1% /doonceaix /dev/nmonlv 1.00 0.03 0.97 4% /var/perf/poa /dev/fslv02 49.50 42.86 6.64 87% /u01 /dev/fslv03 685.00 312.62 372.38 46% /u02 akslltsm:/depot 60.50 43.06 17.44 72% /mnt
my parser in java splits text spacing size. read lines, parser splits string when hee sees @ least 1 space character. can see, there lines inside column (like "gb blocks
" , "mounted on
") can't split want.
what want set column width (2+ space characters) , program parse successfully.
catch special cases , fill in spaces, adjust columns, undo did in first step.
e.g.
step one: sed -e 's/gb blocks/gb_blocks/' -e 's/mounted on/mounted_on/' second step: normal program adjusts columns third step: sed -e 's/gb_blocks/gb blocks/' -e 's/mounted_on/mounted on/'
then pipe them together:
sed -e ... | <your prog> | sed -e ...
this general technique type of situation. if input isn't able parsed (using whatever definition need @ time), alter input work, parse it, reverse first alteration.
Comments
Post a Comment