Hi,
I need to assign values from a lines in a file into variables in unix, i am using Korn shell.
I tried the below script from posts but i am unable to fetch every value in a variable.
#! /usr/bin/ksh
#for file in test.txt; do
IFS=$'\|'
I=1
while read -a val
do
echo "val[${I}]=${val[${I}]}"
I=` expr ${I} + 1 `
done < fs_mail.txt
#done
but i am getting error.
test_script_2.ksh[7]: read: -a: unknown option
Usage: read [-ACprsv] [-d delim] [-u fd] [-t timeout] [-n nchar] [-N nchar] [var?prompt] [var ...]
I tried this it worked but my file is pipe | separated ,variable are not as i expected.
#!/usr/bin/ksh
I=1
for WORD in $(cat test.txt); do
WORDS[$I]=$WORD
echo "WORDS[$I]=$WORD"
I=$((I + 1))
done
File will look like
line1|111|22|33|44|55|aa|bb|cc
line2|dd|ee|ff|gg|ii|jj|kk|ll|mm|nn|oo|pp
Could anyone Please advise, how to achive.
Thanks,
Regards,
karthikram