我怎样才能从文件中读取单词(而不是线)? [英] How can I read words (instead of lines) from a file?

查看:105
本文介绍了我怎样才能从文件中读取单词(而不是线)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我读这使用从文本文件中读取字符庆典。我wanto知道如何做到这一点,但在每行字数阅读。

Ok I'm read this Read characters from a text file using bash. I wanto to know how to do that but to read in words per line.

example text
example1 text1
example2 text2
example3 text3

谁能解释这样对我?或者告诉我一个简单的例子?
谢谢!

Can anyone explain that to me? or show me an easy example? thanks!

推荐答案

默认命令读取整行。因此,解决办法可能就是阅读整条生产线,然后把它分解与例如,空格

The read command by default reads whole lines. So the solution is probably to read the whole line and then split it on whitespace with e.g. for:

while read line; do
    for word in $line; do
        echo "word = '$word'"
    done
done

这篇关于我怎样才能从文件中读取单词(而不是线)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆