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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

array lenght

Status
Not open for further replies.

domenicodl

Programmer
Jul 2, 2011
15
IT
Hi,
how do you count the length of an array?
The command "length" works for strings, what I do is to scan the array with a for loop and increment a counter by one until the end of the array. Is there any other smarter way to do it ?
Thank you in advance.
 
Hi

domenicodl said:
Is there any other smarter way to do it ?
In your earlier threads you wrote that your operating system is Ubuntu. Although you not specified which Awk implementation are you using, most probably it is GNU Awk.
man gawk said:
[tt]length([s])
Return the length of the string s, or the length of $0 if s is not supplied. As a non-standard extension, with an array argument, length() returns the number of elements in the array.[/tt]
Regarding a POSIX standard way, I know about none.


Feherke.
 
Hi

3.1.6 is enough for this :
man gawk ( version 3.1.6 ) said:
[tt]length([s])
Returns the length of the string s, or the length of $0 if s is not supplied. Starting with version 3.1.5, as a non-standard extension, with an array argument, length() returns the number of elements in the array.[/tt]
( YMMV, but I would do anything to update to 4.0.0 as it contains many NEWS. )


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top