- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Help with AWK script
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
Forums
Discussions
Discussions
Discussions
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
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
02-10-2003 08:58 AM
02-10-2003 08:58 AM
I have written a small script to strip out TOTAL REAL-MIN and HOG-FACTOR from the monthly acct file, fiscrptXX. I run into problems when the numbers in some columns are so large that they run together. I have attached a small portion of an acct file with the problem data and also the script I am using which uses AWK to print out the values from column 5 and 8. Can I instruct awk to read column five as a floating point number with 2 decimal points?? Can I re-format the monacct output with wider column widths?? What is the best way to get around this?
Any thoughts are greatly appreciated!
Thanks,
Theresa
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2003 09:05 AM
02-10-2003 09:05 AM
Re: Help with AWK script
awk 'print substr($0,39,13),substr($0,68,12)'
to print those column positions.
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2003 09:25 AM
02-10-2003 09:25 AM
Re: Help with AWK script
You can always use the shell to reformat the overlapping columns of your file:
#!/usr/bin/sh
while read X
do
A=`echo "${X}"|cut -c1-51`
B=`echo "${X}"|cut -c52-`
echo "${A} ${B}"
done < infile > outfile
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2003 10:08 AM
02-10-2003 10:08 AM
Re: Help with AWK script
#!/use/bin/perl
use strict;
use warnings;
my $f1 = "/var/adm/acct/fiscal/fiscrpt".((localtime)[4]+1);
my $f2 = $f1 . "_numbers";
open my $F, "< $f1" or die "$f1: $!";
while (<$F>) {
my ($cmd, $n, $tot, $cpu, $real, $mean, $min, $hog, $xfer, $read) =
grep s/^\s*//,
unpack "A9 A7 A12 A10 A13 A8 A8 A8 A13 A11", $_;
$real =~ m/^\d/ or next;
printf "%13s %8s\n", $real, $min;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2003 10:19 AM
02-10-2003 10:19 AM
Re: Help with AWK script
Thanks for the ideas, but unfortunately once the line is read into $X, it loses all of its nice formatting. I've attached what $X looks like after the "read". Unless character position can be used on the "read", it is virtually useless after the fact. The only way I can think to break up the numbers that run together is to read up to only 2 places after a decimal point, but I do not know if this is possible.
Procura, I do not know anything about Perl, but would that script take care of the issues I've outlined in my response?? How does that script deal with the numbers that have run together?
Any other ideas??
Thanks Again,
Theresa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2003 10:24 AM
02-10-2003 10:24 AM
SolutionPlease run the small script I suggested. By *double-quoting* the variables in the 'echo' statements, I have preserved the formatting you had in the input file while adding one blank character to separate the merged fields.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2003 10:29 AM
02-10-2003 10:29 AM
Re: Help with AWK script
my ($cmd, $n, $tot, $cpu, $real, $mean, $min, $hog, $xfer, $read) =
unpack "A9 A7 A12 A10 A13 A8 A8 A8 A13 A11", $_;
The grep I had in between stripped off the *leading* space for every field. I did this to be able to filter on the wanted columns starting with a digit. If I leave the grep out, I have to change the next line to
$real =~ m/^\s*\d/ or next;
Enjoy, have FUN! H.Merijn (who still wants an option in the ITRC to paste formatted text and prevent clipping the multiple spaces from nicely formatted tables, so I can finally show how well it works)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2003 10:43 AM
02-10-2003 10:43 AM
Re: Help with AWK script
Sorry I did not look more closely at your response the first time. It does exactly what I need. I have a few other special cases to handle, but I think I can take care of those. You wear your ITRC Olympian status well!!
Thanks for the explanation, Procura. Looks like a foreign language to me since I do not know Perl, but I may check into it more closely if I have more time. Thanks for your input!
As usual, ITRC comes to the rescue!
Thanks,
Theresa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2003 10:54 AM
02-10-2003 10:54 AM
Re: Help with AWK script
Check out
http://www.perl.com/pub/r/916
This describes a module you can use within perl to process the "acct" info. This way you can munge the data how ever you like and not worry about number field "overflows"
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2003 11:32 AM
02-10-2003 11:32 AM
Re: Help with AWK script
Thanks anyway!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2003 11:39 AM
02-10-2003 11:39 AM
Re: Help with AWK script
to direct awk to read/print a column as floating decimal, you can use the format like in C, in your case, you can add format like this:
awk '{print "%.2f\n", $5}'
I tested it with your sample data, and got the following output of column 5:
1060.77
144331.87
181.58
73304.79
3542544.38
1421.01
194178.39
27.79
17.78
0.00
thanks,
Gary