I’m trying to transform a given line to an array, for example this line :
My first\t \tHello world
to the following ksh/bash array:
[0]="My first"
[1]=""
[2]="Hello world"
My code:
TAB=`printf '\011'`
query()
{
echo "$1"|awk -F"$TAB" '
{
for(i = 0; i < NF; i++)
QueryArray[i]=$i
}';
}
line=`head -n 1 myFile`
typeset -a QueryArray;
query "$line"
echo "Array length: ${#QueryArray[*]}"
echo "- " ${QueryArray[0]}
echo "- " ${QueryArray[1]}
echo "- " ${QueryArray[2]}
but doesn’t work, any suggestions?
Thanks.
I have an older ksh that does not understand
$'ANSI'strings, so:for bash:
I’m getting the same result ar Arnaud’s comment to David: with “word\t\tword”, the middle field is being dropped. I don’t see that with a different delimiter such as colon.
ksh
bash