Computing.Net > Forums > Unix > Awk script for printing unique valu

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Awk script for printing unique valu

Reply to Message Icon

Name: higgies
Date: May 26, 2005 at 07:10:30 Pacific
OS: SuSe
CPU/Ram: N/A
Comment:

Hello!

I am trying to write an awk script which find a value, gets the value next to it, then prints out the second value and the number of times it occurs. So far, I have been able to find the value, store the value next to it in an array, and print out the values stored in an array. Unfortunately, I'm having trouble storing only the first occurance of the second value and counting the occurances. Any help?!

Here is a sample of what I've got so far:

BEGIN { i = 1}
{
if (/Data written/){
tape_no = substr($8,0,6);
if ( !( tape_no in barcode))
{
barcode[i] = tape_no;
i++;
}
}
}
END {
for ( y in barcode )
printf( "Barcode: %s\n",barcode[y] )
}

A sample of the lines in the input file is here:

[2005/04/11 14:08:29, ivdserver.ivdnet, 016015, BEA, /dev/sg12, 20050411000021, 000176] Vol 2: Data written: 65936 KB (5094 KB/s).
[2005/04/11 14:11:24, ivdserver.ivdnet, 016066, BEA, /dev/sg12, 20050411000024, 000176] Vol 2: Data written: 58608 KB (5420 KB/s).
[2005/04/11 14:11:51, ivdserver.ivdnet, 016080, BEA, /dev/sg12, 20050411000019, 000176] Vol 2: Data written: 170928 KB (10656 KB/s).
[2005/04/11 14:12:27, ivdserver.ivdnet, 016096, BEA, /dev/sg12, 20050411000026, 000176] Vol 2: Data written: 17104 KB (5712 KB/s).
[2005/04/11 14:12:50, ivdserver.ivdnet, 016111, BEA, /dev/sg12, 20050411000023, 000176] Vol 2: Data written: 107440 KB (9730 KB/s).
[2005/04/11 14:14:30, ivdserver.ivdnet, 016153, BEA, /dev/sg12, 20050411000028, 000176] Vol 2: Data written: 17104 KB (2337 KB/s).
[2005/04/11 14:14:45, ivdserver.ivdnet, 016168, BEA, /dev/sg12, 20050411000025, 000176] Vol 2: Data written: 85472 KB (10245 KB/s).
[2005/04/11 14:15:39, ivdserver.ivdnet, 016204, BEA, /dev/sg12, 20050411000027, 000176] Vol 2: Data written: 68368 KB (9881 KB/s).



Sponsored Link
Ads by Google

Response Number 1
Name: higgies
Date: May 26, 2005 at 07:41:49 Pacific
Reply:

Got it! Sorry...

{
if (/Data written/){
tape_no = substr($8,0,8);
if ( !( tape_no in barcode))
barcode[tape_no] = 1;
else
barcode[tape_no] = barcode[tape_no]+1
}
}
END {
for ( y in barcode )
printf( "Barcode: %s , # of Writes: %i\n",y,barcode[y] )
}


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Awk script for printing unique valu

Parameter file for a shell script www.computing.net/answers/unix/parameter-file-for-a-shell-script/6026.html

Shell Script & Awk www.computing.net/answers/unix/shell-script-amp-awk/4594.html

tweaking William's awk script www.computing.net/answers/unix/tweaking-williams-awk-script/5174.html