LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   problem exporting result of awk to an array... (https://www.linuxquestions.org/questions/linux-newbie-8/problem-exporting-result-of-awk-to-an-array-703654/)

mitramcc 02-10-2009 11:25 AM

problem exporting result of awk to an array...
 
cmd=$1 # first argument
str=( $2 ) # second argument
pattern=$3 # third argument

for (( i=0 ; i<${#str[*]} ; i=i+1 ))
do
echo ${str[${i}]}|awk -F $pattern '{print NF-1}'
var[${i}]=`${str[${i}]}|awk -F $pattern '{print NF-1}'
done

echo ${var[*]}



when i do :

:~/Desktop$ ./tst.sh -r 'asdasd asdasd' asd
the result is
2
2

-----------------------------------------------
the var stills empty :/...

can somebody help me :/ i am to noob :/

jschiwal 02-10-2009 11:32 AM

You have a space between the hyphen and the F argument, no closing single quote in the first awk line, and no third argument to use as the separator.

mitramcc 02-10-2009 11:47 AM

Quote:

Originally Posted by jschiwal (Post 3438609)
You have a space between the hyphen and the F argument, no closing single quote in the first awk line, and no third argument to use as the separator.

the first to mistakes it was error of copy, bc i had that right :/...

about the third, the third argument isn't the asd?
1st -r
2nd asdasd asdasd
3rd asd

thx


All times are GMT -5. The time now is 12:01 PM.