From: Luuk Date: 2011-05-19T02:15:27+09:00 Subject: Re: Linux utility with reverse index facility? On 18-05-2011 05:40, Robert Nichols wrote: > On 05/16/2011 05:38 AM, no.top.post@gmail.com wrote: >> awk&stuff can "give me the the Nth element", >> but, without writing your own search-loop, >> what can "give me the index of the 'element' >> which is" ? >> >> I think it's called 'reverse indexing' ? > > In awk, it's just as easy to build an array where your "elementValues" > are the indices and the values stored in the array are ordinal numbers. > I,e., instead of > myArray[n++] = "cheese" > have > myArray["cheese"] = n++ > > Now you can use myArray["something"] in an expression and get back > the number that was stored for that string (or a null string equivalent > to arithmetic 0 if that index was never stored). > echo "abcde c"| awk '{ for (x=0;x