I have this sample text file text.txt that is in the form
fruits vegetables
apples cucumbers
oranges squash
and it is tab delimited.
I would like to loop through the file line by line, and extract each column value.
Below is the code the code I have tried.
while read p
do
echo "Line"
fruit="$(cut -f 1 $p)"
echo "${fruit}"
done <test.txt
My expected output should be something like:
Line
fruits
Line
apples
Line
oranges
Instead I get this output:
Line
cut: fruits: No such file or directory
cut: vegetables: No such file or directory
Line
cut: apples: No such file or directory
cut: cucumbers: No such file or directory
Line
cut: oranges: No such file or directory
cut: squash: No such file or directory