I have a sentence like
This is for example
I want to write this to a file such that each word in this sentence is written to a s
A couple ways to go about it, choose your favorite!
echo "This is for example" | tr ' ' '\n' > example.txt
or simply do this to avoid using echo unnecessarily:
tr ' ' '\n' <<< "This is for example" > example.txt
The <<< notation is used with a herestring
Or, use sed instead of tr:
sed "s/ /\n/g" <<< "This is for example" > example.txt
For still more alternatives, check others' answers =)