How can I read words (instead of lines) from a file?

前端 未结 7 1850
眼角桃花
眼角桃花 2020-12-16 12:37

I\'ve read this question about how to read n characters from a text file using bash. I would like to know how to read a word at a time from a file that looks like:



        
7条回答
  •  粉色の甜心
    2020-12-16 12:52

    Ordinarily, you should read from a file using a while read -r line loop. To do this and parse the words on the lines requires nesting a for loop inside the while loop.

    Here is a technique that works without requiring nested loops:

    for word in $(

提交回复
热议问题