LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   How to return values into an array using awk (http://www.linuxquestions.org/questions/programming-9/how-to-return-values-into-an-array-using-awk-174681/)

Helene 04-26-2004 08:31 AM

How to return values into an array using awk
 
Hi,

Is it possible to rewrite this while-loop to make it work?

i=1
while i < 10
{
myArr[i]=`awk -v var=$line '{ lines[$0]++ } END { for( line in lines ) print line }' myFile`
i = `expr $i + 1`
}

Am I on the right track at all? This syntax is complicated.. :mad:
I want the array to be filled up with the 10 first records of my file.

-Helene

arvind_sv 05-01-2004 10:05 PM

Hi,

I'm assuming that you have a recent version of bash or such. How about this?

Code:

line=3
set -A myarr `awk -v var=$line '{if (NR == var) {line=$0; exit;}} END {print line}' myFile`

Arvind


All times are GMT -5. The time now is 05:42 AM.