My program output text file data in columns format. My problem is the column headers do not align with the data and if filesystem and Mounted On columns pathname are too long the text will not wrap.
Is there any function in Unix that I can use in my code that will align the data for each column with the correct headers? Is there any script in Unix that will wrap text if the pathname is too long?
1) The attachment named data not aligned with column headers shows the
current results.
2) The attachment named how i want the results. Is want I am looking for.
3) The attachment named disk_2016.11.29.txt is the file that is read in the code
here is my code
#!/bin/ksh
fpath=/sas/scripts/OPTUMize/output/disk_utilization
# get input
echo "Enter Group name (ex: hasasvmi): "
read gname
echo "Enter Current Date( ex: 10/01/2016): "
read cdate
# format: 09/30/2016
# parse date
yyyy=$(echo ${cdate} | cut -d"/" -f3)
dd=$(echo ${cdate} | cut -d"/" -f2)
mm=$(echo ${cdate} | cut -d"/" -f1)
echo "Enter number of records (ex: 1-1000): "
read nrec
# construct file name to parse
diskfile=${fpath}/disk_${yyyy}.${mm}.${dd}.txt
# check if file exists
if [ ! -f ${diskfile} ]
then
echo File: ${diskfile} not found. Exiting.
exit 1
fi
# generate output on screen - TAB separated (OFS)
awk -v gname=${gname} -v OFS="\t" 'BEGIN { print "Filesystem", "blocks", "Free", "% Used", "%Iused", "Mounted on", "Date", "Time" }
$0 ~ gname { gsub(/_/,""'"OFS"'"",$7); print $1, $2, $3, $4, $5, $6, $7 }' ${diskfile} | head -$(expr ${nrec} + 1)