The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 07-02-2009
shellwell shellwell is offline
Registered User
  
 

Join Date: May 2009
Posts: 15
awk - array elements as condition

Hi,

can I use array elements ( all ) in conditional statements?
the problem is ,the total number of elements is not known.

e.g

A is an array with elements - 1,2,3

now if i want to test if the 1 st field of input record is either 1,2 or 3, i can do something like this

Code:
if ( $1 ~ /^A[1]$|^A[2]$|^A[3]$/) { print  YES }
but i want something like..

Code:
if ( $1 ~ /^A[1]$|^A[2]$|^A[3]$/| logical OR till array's last element) { print  YES }

Is that possibe?