I am struggling around with awk and want to save the awk output separated by the delimiter to array. So just to have this working:
array[index]=$line
with $line
equal value between separator '[[:blank:]]{2,}'
in the desired file.
I tried already multiple solutions like:
myarr=$(/usr/xpg4/bin/awk -F '[[:blank:]]{2,}' 'FNR > 4 { for (i=1; i<=NF; i++) if ($i != "") print $i;}' my-file)
or
array=()
counter=0
/usr/xpg4/bin/awk -F '[[:blank:]]{2,}' 'FNR > 4 { for (i=1; i<=NF; i++) if ($i != "") print $i;}' my-file | while read -r line; do
array[counter]=$line
counter=$((counter+1))
done
echo ${#array[@]}
echo ${array[1]}
none of them produce the desired result. But when I modify the second case and echo
the $line
and the $counter
I get the array, but it is not the case for a large file, I just do not want to output the whole lines to the console to get my array filled up - it makes no sense for me:
This works -> but uggly/bad performance for large files
array=()
counter=0
/usr/xpg4/bin/awk -F '[[:blank:]]{2,}' 'FNR > 4 { for (i=1; i<=NF; i++) if ($i != "") print $i;}'my-file | while read -r line; do
echo $line
echo $counter
array[counter]=$line
counter=$((counter+1))
done
echo ${#array[@]}
echo ${array[1]}