Issue
The content of text.txt
is:
absolute abstract academic accepted accident
I'm trying to loop through each word and print it so I can get an output like this:
absolute
abstract
academic
accepted
accident
I tried using cat
but it starts from the field 1
so it end up ignoring a word
words="$(cat text.txt | wc -w)"
for ((i=0; i<$words; i++)); do
cut -d' ' -f$i text.txt
done
I think awk
could also be useful but I don't know very well its syntax.
awk '{print $'$i'}'
I tried something like this but the output was a mess.
Solution
You over-complicate it, bash for
loop can go through a list of words:
for word in $(cat text.txt); do
echo "$word"
done
Answered By - redseven Answer Checked By - Timothy Miller (WPSolving Admin)