Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
11-30-2016, 12:20 PM
|
#1
|
LQ Newbie
Registered: Sep 2015
Posts: 7
Rep: 
|
Disk Ram Peak
OS is AIX
My program is working but I have one problem. When the results output to the screen, the Column headers and data don't align correctly. How can I fix this in my code?
please see attachments
here is my code
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)
|
|
|
11-30-2016, 12:36 PM
|
#2
|
LQ Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,594
|
Quote:
Originally Posted by dfn
OS is AIX
|
You really should be posting AIX questions in the AIX forum.
Quote:
My program is working but I have one problem. When the results output to the screen, the Column headers and data don't align correctly. How can I fix this in my code?
|
Read up on the printf statement in ksh:
http://www.ibm.com/support/knowledge...l_enhanced.htm
|
|
|
11-30-2016, 12:36 PM
|
#3
|
Senior Member
Registered: Sep 2010
Location: Lawrence, New Zealand
Distribution: Slackware
Posts: 1,077
|
AIX != Linux
This would probably be better asked in the AIX forum.
Last edited by notKlaatu; 11-30-2016 at 12:38 PM.
Reason: /Other *nix/AIX/
|
|
|
12-01-2016, 07:15 AM
|
#4
|
Senior Member
Registered: Dec 2011
Location: Simplicity
Distribution: Mint/MATE
Posts: 3,027
|
This one reads the $diskfile twice; the first time to determine the field width.
Code:
awk -v gname="$gname" '
$0!~gname {next}
NR==FNR {
# first read: get the field width into L[]
if (NF>nf) nf=NF
for (i=1; i<=NF; i++) { len=length($i); if (len>L[i]) L[i]=len }
next
}
# second read
hdone!=1 {
# print the header
split ("Filesystem blocks Free Used %Iused Mounted_on Date Time",H)
for (i=1; i<=NF; i++) printf "%*s ",L[i],H[i]
printf "\n"
hdone=1
}
{
# print the fields
for (i=1; i<=NF; i++) printf "%*s ",L[i],$i
printf "\n"
}
' "$diskfile" "$diskfile"
|
|
|
All times are GMT -5. The time now is 04:44 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|