MLUG: RE: [MLUG] count fields
RE: [MLUG] count fields
Email address obfuscation in effect -- please click here to turn it off.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
I think he's asking about database queries, not a file.
If so, there is no built-in method for this. You will have to query all fields, and loop through counting nulls and ZLTs.

> On Tue, 7 Oct 2003, mehmood hasan wrote:
> 
> > I want to count No. of filled fields in any row
> > i am seeking a query that returns me the number of filled 
> fields in a row;
> > any one can help me
> 
> It depends on the delimiter.  If the delimiter is white space 
> (spaces and
> tabs), then gawk will do it well (except that it ignores initial white
> space, but that's often a good thing).  I'm assuming you have 
> a text file.
> You do this:
> 
> gawk '{print NF}' filename
> 
> That will give you 'NF' (Number of Fields) for every line of 
> the file.  If
> you are using a single tab as a delimiter, you can do this:
> 
> gawk -F'\t' '{print NF}' filename
> 
> where '-F' allows you to specify a different field delimiter, and '\t'
> represents a tab character.
> 
> If you want to see if all lines have the same number of fields, or you
> want a frequency count, you can do this:
> 
> gawk '{print NF}' filename | sort | uniq -c
> 
> By the way, 'awk' does the same kind of thing as 'gawk', but 
> if you are on
> some unix systems (e.g., Solaris, at least), awk will fail 
> with more than
> something like 32 fields.  Pretty lame.
> 
> Let us know if that doesn't help you.
> 
> Mike
> _______________________________________________
> members mailing list
> EMAIL:PROTECTED
> http://mlug.missouri.edu/mailman/listinfo/members
> 

_______________________________________________
members mailing list
EMAIL:PROTECTED
http://mlug.missouri.edu/mailman/listinfo/members