- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: awk help: summarize list when column X change...
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
тАО12-02-2005 02:22 AM
тАО12-02-2005 02:22 AM
DA-7B 07B D 1 SEAGATE CUDA180 24 173017 450 173145
DA-7B 07B D 2 SEAGATE CUDA180 20 173017 386 173145
DA-7B 07B D 3 SEAGATE CUDA180 20 173017 386 173145
DA-8B 08B C 5 SEAGATE CUDA180 20 173017 386 173145
DA-8B 08B C 8 SEAGATE CUDA180 20 173017 386 173145
DA-8B 08B C 9 SEAGATE CUDA180 20 173017 386 173145
DA-8B 08B D 0 SEAGATE CUDA180 21 173017 383 173145
DA-8B 08B D 1 SEAGATE CUDA180 25 173017 5946 173145
DA-8B 08B D 2 SEAGATE CUDA180 21 173017 383 173145
DA-8B 08B D 3 SEAGATE CUDA180 20 173017 386 173145
DA-9B 09B C 1 SEAGATE CUDA180 21 173017 383 173145
DA-9B 09B C 2 SEAGATE CUDA180 20 173017 386 173145
DA-9B 09B C 3 SEAGATE CUDA180 20 173017 386 173145
DA-9B 09B C 4 SEAGATE CUDA180 20 173017 386 173145
DA-9B 09B C 5 SEAGATE CUDA180 20 173017 386 173145
DA-9B 09B C 8 SEAGATE CUDA180 20 173017 386 173145
DA-9B 09B C 9 SEAGATE CUDA180 20 173017 386 173145
DA-10B 10B C 4 SEAGATE CUDA180 20 173017 386 173145
DA-10B 10B C 5 SEAGATE CUDA180 20 173017 386 173145
DA-10B 10B C 8 SEAGATE CUDA180 20 173017 386 173145
DA-10B 10B C 9 SEAGATE CUDA180 20 173017 386 173145
DA-10B 10B D 0 SEAGATE CUDA180 21 173017 383 173145
DA-10B 10B D 1 SEAGATE CUDA180 21 173017 383 173145
DA-10B 10B D 2 SEAGATE CUDA180 20 173017 386 173145
DA-10B 10B D 3 SEAGATE CUDA180 20 173017 386 173145
DA-10B 10B D 4 SEAGATE CUDA180 20 173017 386 173145
I want to summarize when the "DA" changes.
I want to say:
DA-07B has 4 x SEAGATE CUDA180 Disks.
DA-08b has 4 x .. etc.
How do i do that in "awk"? Is there some way to say "when $1 changes, count up.."? Or do I have to save the value and check every time, etc.?
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-02-2005 02:43 AM
тАО12-02-2005 02:43 AM
Re: awk help: summarize list when column X changes value
Try this:
#!/usr/bin/awk -f
{if (FIRST!=1) {FIRST=1;LAST=$1}}
{if ($1!=LAST) {print LAST," count = ",CNT;CNT=0;LAST=$1}}
{print;CNT++}
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-02-2005 02:43 AM
тАО12-02-2005 02:43 AM
Re: awk help: summarize list when column X changes value
Keep it simple
cat tmp/in|cut -f1 -d " "|sort -u|
while read line
do
let xx=$(grep $line tmp/in|wc -l)
echo $line has $xx $(grep $line tmp/in|
head -n 1|cut -f5-6 -d" ") disks
done
tmp/in is data file containing list shown
Steve Steel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-02-2005 02:58 AM
тАО12-02-2005 02:58 AM
Re: awk help: summarize list when column X changes value
cut -c1 yourfile | sort | uniq -c
Perl can provide a more complete routine-
perl -an -e '$tot{$F[0]}{"$F[4] $F[5]"}++;END {for $DA (sort keys %tot) { for $dsk (sort keys %{$tot{$DA}}) { print "$DA has $tot{$DA}{$dsk} $dsk Disks.\n";}}}' yourfile
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-02-2005 03:05 AM
тАО12-02-2005 03:05 AM
Solutionjust shorter and without awk:
cut -f1 -d " " /tmp/x | sort | uniq -c
mfG nik
- Tags:
- cut
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-02-2005 03:38 AM
тАО12-02-2005 03:38 AM
Re: awk help: summarize list when column X changes value
BTW, you never evaluated the responses in your thread below and I would like to know if you found them helpful. Thanks.
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=976274
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-02-2005 04:58 AM
тАО12-02-2005 04:58 AM
Re: awk help: summarize list when column X changes value
How about this awk construct:
awk '/^DA-[0-9]*B/{line=$5" "$6;if(NF==1){curr=$1;count[curr]++} else{if(curr==$1)count[curr]++;else{curr=$1;count[curr]++}}} END{for(i in count) print i " has", count[i] " x " line " Disks"}'
cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-02-2005 06:43 AM
тАО12-02-2005 06:43 AM
Re: awk help: summarize list when column X changes value
=====================myawkscript=======================
/^DA-[0-9]*B/ {
line=$5" "$6
if ((NF==1)||(curr==$1)) {
curr=$1
count[curr]++
}
else {
curr=$1
count[curr]++
}
}
END{for(i in count) printf("%s has %d x %s Disks\n", i, count[i], line)}
=======================================================
# symdisk | awk -f myawkscript
cheers!