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
Try using :
string="This is for example" printf '%s\n' $string > filename.txt
or taking advantage of bash word-splitting
string="This is for example" for word in $string; do echo "$word" done > filename.txt