print selected lines

Hi everybody:
I try to print in new file selected lines from another file wich depends on the first column.

I have done a script like this:

	lines=( "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "21" "31" "41" "51" "55" "57" "58" )
	${lines[@]}
	for lines in ${lines[@]}
	do
	awk -v  target=$lines  ' $1 == target print $0 ' file1 >> file2
	done

But I have the next error:

./T-eff.sh: 42: Syntax error: "(" unexpected ------ where the line 42 correspond when I declare the array "lines"

Any suggestion?. Thanks in advance :rolleyes:

What shell are you using? In KSH the following works:

set -A lines = 1 2 3 4 5 6 7 8 9 10 11 21 31 41 51 55 57 58
print ${lines[12]}

will print '21'

Hi:
Thanks for your reply. I usually use the sh shell. :rolleyes:

I don't think the bourne shell supports arrays.

Hi again:
I have seen at "Advanced Bash-Scripting Guide" by Mendel Cooper that it is possible to use arrays on bourne shell scripts.

Bash is the bourne again shell, the newer version of the bourne shell, or sh.

If you want bash, start your script with #!/bin/bash otherwise if no shell is selected sh will be used, and that doesn't support arrays as far as I know.

:b: I have done, I have changed:

#!/bin/sh

for

#!/bin/bash

and now it works correctly. Thnaks a lot. :wink: