Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Disk Ram Peak

Posted on 2016-11-30
1
Medium Priority
?
80 Views
Last Modified: 2016-12-01
OS is AIX

My code works but I am having one problem. When the results output to the screen, the column headers and data are not aligned correctly.  How can this be corrected in the code so that the column headers align with the data?

Please see attachments


Here is the code
!/bin/ksh
 
 
 
fpath=/sas/scripts/OPTUMize/output/disk_utilization
 
# get input
echo "Enter Group name: "
read gname
 
echo "Enter Current Date: "
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: "
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)
 

Open in new window

disk_2016.11.29.txt
data-not-aligned-with-column-headers.txt
how-i-want-results.txt
0
Comment
Question by:dfn48
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 17

Accepted Solution

by:
Gerald Connolly earned 2000 total points
ID: 41908447
Why not print the headers as one string?
so instead of:            print "Filesystem", "blocks", "Free", "% Used", "%Iused", "Mounted on", "Date", "Time" }
something like this: print "Filesystem       blocks   Free   % Used    %Iused       Mounted on         Date     Time" }

all you need to do is adjust the spacing between the headers then
0

Featured Post

Python: Series & Data Frames With Pandas

Learn the basics of Python’s pandas library of series & data frames and how we can use these tools for data manipulation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question