- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: awk parsing
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-18-2002 12:13 PM
тАО04-18-2002 12:13 PM
I posted a question how to calculate sum of all columns. It really helped me. Thank you.
I have a little different problem though: here an possible file I could have:
/dev/vg00/lvol3 155648 45189 103603 2402
/dev/vg00/lvol1 99669 36453 53249 16081
/dev/vg00/lvol8 819200 710685 10199 19967
/dev/vg00/lvol7 819200 496611 30248 18973
/dev/vg01a/lvol3 155648 45189 103603 2402
/dev/vg01a/lvol1 99669 36453 53249 16081
/dev/vg01a/lvol8 819200 710685 10199 19967
/dev/vg01a/lvol7 819200 496611 30248 18973
and I need the following output:
/dev/vg00/lvol3 155648 45189 103603 2402
/dev/vg00/lvol1 99669 36453 53249 16081
/dev/vg00/lvol8 819200 710685 10199 19967
/dev/vg00/lvol7 819200 496611 30248 18973
Total(vg00): xxxxx xxxxx xxxx xxxx
/dev/vg01a/lvol3 155648 45189 103603 2402
/dev/vg01a/lvol1 99669 36453 53249 16081
/dev/vg01a/lvol8 819200 710685 10199 19967
/dev/vg01a/lvol7 819200 496611 30248 18973
Total(vg01a): xxxxx xxxxx xxxx xxxx
Any ideas how to use awk in this case?
Thanks a lot!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-18-2002 12:18 PM
тАО04-18-2002 12:18 PM
Re: awk parsing
Also change tle bdf to cat your file.
bdf|grep -v Filesystem|tr -s " " " "|cut -d" " -f 1-4|sort|
awk 'BEGIN {
prev="";
totals[0]=0;
totals[1]=0;
totals[2]=0;
gtotals[0]=0;
gtotals[1]=0;
gtotals[2]=0;
printf("%4s %14s %14s %14s\n","VG","Size","In use","Available");
}
{split($1,curr,"/");
if (prev!="" && prev!=curr[3])
{printf("%4s %14d %14d %14d\n",prev,totals[0],totals[1],totals[2]
);
gtotals[0]+=totals[0];
gtotals[1]+=totals[1];
gtotals[2]+=totals[2];
totals[0]=0;
totals[1]=0;
totals[2]=0;
}
prev=curr[3];
totals[0]+=$2;
totals[1]+=$3;
totals[2]+=$4;
}
END {
gtotals[0]+=totals[0];
gtotals[1]+=totals[1];
gtotals[2]+=totals[2];
printf("%4s %14d %14d %14d\n",prev,totals[0],totals[1],totals[2]);
printf("%4s %14s %14s %14s\n","----","--------------","-------------
-","--------------");
printf("%4s %14d %14d %14d\n","Totl",gtotals[0],gtotals[1],gtotals[2
]);
}'
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-18-2002 12:21 PM
тАО04-18-2002 12:21 PM
Re: awk parsing
Wow, thanks a lot a such big script!
Unfortunately, I cannot use bdf, since the file I get is from another system.
So, I just have file.txt....
I assume your script should from simple file as well?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-18-2002 12:28 PM
тАО04-18-2002 12:28 PM
Re: awk parsing
Along our earlier lines, for example:
# awk 'BEGIN{min=2;max=5};/vg01/ {for (i=min;i<=max;i++) a[i]+=$i};END {for (i=min;i<=max;i++) print a[i]}' /tmp/data
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-18-2002 12:31 PM
тАО04-18-2002 12:31 PM
Solutiontr -s " " " "|cut -d" " -f 1-4|sort|
awk 'BEGIN {
prev="";
totals[0]=0;
totals[1]=0;
totals[2]=0;
gtotals[0]=0;
gtotals[1]=0;
gtotals[2]=0;
printf("%24s %14s %14s %14s\n","VG","Size","In use","Available");
}
{
split($1,curr,"/");
if (prev!="" && prev!=curr[3])
{printf("%24s %14d %14d %14d\n",prev,totals[0],totals[1],totals[2
]);
printf "\n";
gtotals[0]+=totals[0];
gtotals[1]+=totals[1];
gtotals[2]+=totals[2];
totals[0]=0;
totals[1]=0;
totals[2]=0;
}
printf("%24s %14d %14d %14d\n",$1,$2,$3,$4);
prev=curr[3];
totals[0]+=$2;
totals[1]+=$3;
totals[2]+=$4;
}
END {
gtotals[0]+=totals[0];
gtotals[1]+=totals[1];
gtotals[2]+=totals[2];
printf("%24s %14d %14d %14d\n",prev,totals[0],totals[1],totals[2]);
printf("%24s %14s %14s %14s\n","----","--------------","------------
--","--------------");
printf("%24s %14d %14d %14d\n","Totl",gtotals[0],gtotals[1],gtotals[
2]);
}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-18-2002 12:38 PM
тАО04-18-2002 12:38 PM
Re: awk parsing
Same like before ...
awk '/vg00/{t1=t1+$2;t2=t2+$3;t3=t3+$3;t4=t4+$4;} END {print "Total(vg00): ", t1,t2,t3,t4}' testfile
awk '/vg01a/{t1=t1+$2;t2=t2+$3;t3=t3+$3;t4=t4+$4;} END {print "Total(vg01a): ", t1,t2,t3,t4}' testfile
Thanks,
Shabu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-18-2002 12:52 PM
тАО04-18-2002 12:52 PM
Re: awk parsing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-18-2002 12:57 PM
тАО04-18-2002 12:57 PM
Re: awk parsing
If you want this in the format that you specified ... execute this script:
prompt>cat myscript
-------------
#!/bin/ksh
rm -f /tmp/testfile.out
grep "vg00" testfile >> /tmp/testfile.out
echo " " >> /tmp/testfile.out
awk '/vg00/{t1=t1+$2;t2=t2+$3;t3=t3+$3;t4=t4+$4;} END {print "Total(vg00): ", t1,t2,t3,t4}' testfile >> /tmp/testfile.out
echo " " >> /tmp/testfile.out
grep "vg01a" testfile >> /tmp/testfile.out
echo " " >> /tmp/testfile.out
awk '/vg01a/{t1=t1+$2;t2=t2+$3;t3=t3+$3;t4=t4+$4;} END {print "Total(vg01a): ", t1,t2,t3,t4}' testfile >> /tmp/testfile.out
-------------
prompt>chmod 755 myscript
prompt>./myscript
prompt>cat /tmp/testfile.out
Thanks,
Shabu