In my file mytxt
:
field1 field2
------ -------
this are numbers 12345
this letters abc def ghi
Let's say I want to store the first field in an array:
i=0
while read line; do
field_one[$i]=$(echo $line | awk '{print $1}')
echo ${field_one[i]}
((i++))
done < mytxt
That would give me the this
two times in the output.
Any ideas of how could I store them in an array and get the output:
this are numbers
this letters
I have tried changing delimiters, squeezing spaces, and using sed
, but I'm stuck. Any hint would be appreciated.
My final goal is to store both fields in an array.