Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

suggestions on how to go about this type of "reporting"?

Status
Not open for further replies.

spyghost

Technical User
Jan 17, 2003
52
HK
hi,

i am dealing with this kind of table in text (space delimited)

full UNIX Daily Backup Pool
0% Windows Daily Backup Pool
23% UNIX Monthly Backup Pool
full Windows Weekly Backup Pool
5% Test Backup Pool
...
etc

what i am planning to do is to generate this kind of format:
Name Full Partially Full Free Total
UNIX Daily Backup Pool 3 5 5 13
UNIX Monlty Backup Pool 5 2 5 12
...

the problem that i am actually encountering is that there are only actually 2 colums, but since it is space delimited, awk sees more than two columns. (i can't modify the program that generates this output, its unmodifiable). how would i go about with dealing with only 2 columns?

right now, i am looking into using 2 dimensional arrays to hold the number of counts. is that efficient enough for the problem?

suggestions are highly apprciated... thanks :)
 
A starting point:
nawk '{a=$1;$1="";b[$0]=b[$0]"\t"a}END{for(i in b)print i,b}' /path/to/input

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
[tt]
BEGIN { FS = "^ *full +|% +" }

$2 {
type[$2]++
if ( ""== $1 )
status = "full"
else if (0==$1)
status = "free"
else
status = "part"
counts[$2,status]++
}

END {
fmt = "%-30s%5s%13s%6s%7s\n"
printf fmt,"Name","Full","Part. full","Free","Total"
for (k in type)
printf fmt, k, counts[k,"full"], counts[k,"part"],
counts[k,"free"], type[k]
}
[/tt]
Let me know if this works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top