LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 11-30-2016, 01:20 PM   #1
dfn
LQ Newbie
 
Registered: Sep 2015
Posts: 7

Rep: Reputation: Disabled
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)
Attached Files
File Type: txt data not aligned with column headers.txt (511 Bytes, 11 views)
File Type: txt how i want results.txt (552 Bytes, 5 views)
File Type: txt disk_2016.11.29.txt (29.2 KB, 36 views)
 
Old 11-30-2016, 01:36 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 25,392

Rep: Reputation: 7569Reputation: 7569Reputation: 7569Reputation: 7569Reputation: 7569Reputation: 7569Reputation: 7569Reputation: 7569Reputation: 7569Reputation: 7569Reputation: 7569
Quote:
Originally Posted by dfn View Post
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
 
Old 11-30-2016, 01:36 PM   #3
notKlaatu
Senior Member
 
Registered: Sep 2010
Location: Lawrence, New Zealand
Distribution: Slackware
Posts: 1,075

Rep: Reputation: 725Reputation: 725Reputation: 725Reputation: 725Reputation: 725Reputation: 725Reputation: 725
AIX != Linux

This would probably be better asked in the AIX forum.

Last edited by notKlaatu; 11-30-2016 at 01:38 PM. Reason: /Other *nix/AIX/
 
Old 12-01-2016, 08:15 AM   #4
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,136

Rep: Reputation: 953Reputation: 953Reputation: 953Reputation: 953Reputation: 953Reputation: 953Reputation: 953Reputation: 953
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"
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Ram disk Fixit7 Ubuntu 6 10-07-2016 09:13 PM
Disk Throughput Avg & Disk Througput Peak in AIX smilemukul AIX 1 08-14-2013 01:49 PM
Anyone know of something like a disk-backed RAM disk? dchicks Linux - Kernel 2 11-04-2009 05:21 PM
Ram disk consty Red Hat 1 05-11-2005 08:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration