Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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).

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] )
}

![]() |
![]() |
![]() |

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