Here is the script I am using and this is working fine:
# This is a test file which we are creating and this will be used to create the shell array
cat > test.txt <<End-of-message
1A|1B|1C|1D
2A|2B|2C|2D
3A|3B|3C|3D
4A|4B|4C|4D
End-of-message
set -A col1_arr `awk 'BEGIN { FS = "|" }{print $1}' test.txt`
i=0
while [ $i -lt ${#col1_arr[@]} ]
do
echo "Column 1 is:${col1_arr[$i]}"
(( i=i+1 ))
done
rm test.txt # delet the test file
I do not want to hard-code test.txt and want to be able to pass it as a variable. Please advise.