I am hitting my head against the wall for something trivial, yet I don’t know why it is not allowing me to build an array by reading each row from a file before printing it back out on AIX 6.x.
Employee.txt
1|Sam|Smith|Seatle
2|Barry|Jones|Seatle
3|Garry|Brown|Houston
4|George|Bla|LA
5|Celine|Wood|Atlanta
6|Jody|Ford|Chicago
bash-4.3$ awk 'BEGIN { FS="|" } { employee[$1]=$0; next } { for (index=0; index<=FS; index++) print index ":" employee[index] }' Employee.txt
awk: cmd. line:1: BEGIN { FS="|" } { employee[$1]=$0; next } { for (index=0; index<=FS; index++) print index ":" employee[index] }
awk: cmd. line:1: ^ syntax error
awk: cmd. line:1: error: invalid subscript expression
Got the same error using a different for loop.
bash-4.3$ awk 'BEGIN { FS="|" } { employee[$1]=$0 } END { for (index in employee) { print employee[index] } }' Employee.txt
awk: cmd. line:1: BEGIN { FS="|" } { employee[$1]=$0 } END { for (index in employee) { print employee[index] } }
awk: cmd. line:1: ^ syntax error
awk: cmd. line:1: error: invalid subscript expression