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!

awk script to parse file of tables and record count.

Status
Not open for further replies.

beezey

MIS
Sep 24, 2003
1
US
I'm sorry to ask what is possibly a very, very easy question. However, we just lost an employee that did this before and I am not sure how to accomplish this:

I have files that have the format of:

tablename1:
value, value, value
value, value, value
value, value, value
value, value, value

tablename2:
value, value, value
value, value, value
value, value, value


I need to write an awk script that will printout the table name and the number of records for each table. I have tried to use the NR variable but I can't get it to set back to 0.

Any help will be very greatly appreciated.
 
The method you propose doesn't work. Awk does not use
fseek() to realign NR with previous records,etc..

The usual method is to use something like this.

Code:
{
 if ($0 ~ /.*:$/) {sub(/:/,"",$0); print "Tablename: ",$0 ; getline}
     print
}
 
NR is a builtin variable you can't change.
Just use a counter variable you can reset when you want.

Hope This Help
PH.
 
nawk -f beezey.awk myFile.txt

#------------beezey.awk
BEGIN {
FS=RS=""
}

{
printf("table->[%s] recordsNum->[%d]\n", $1, NF-1);
}


vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top