system
October 8, 2007, 3:57am
1
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:
rein
October 8, 2007, 4:51am
2
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'
system
October 8, 2007, 4:55am
3
Hi:
Thanks for your reply. I usually use the sh shell. :rolleyes:
rein
October 8, 2007, 5:07am
4
I don't think the bourne shell supports arrays.
system
October 8, 2007, 5:21am
5
Hi again:
I have seen at "Advanced Bash-Scripting Guide" by Mendel Cooper that it is possible to use arrays on bourne shell scripts.
rein
October 8, 2007, 5:40am
6
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.
system
October 8, 2007, 5:50am
7
I have done, I have changed:
#!/bin/sh
for
#!/bin/bash
and now it works correctly. Thnaks a lot.