Each word on a separate line

前端 未结 7 1283
囚心锁ツ
囚心锁ツ 2021-01-11 09:36

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

7条回答
  •  被撕碎了的回忆
    2021-01-11 10:33

    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
    

提交回复
热议问题