echo from lines of a file

风流意气都作罢 提交于 2019-12-30 08:53:20

问题


i have a file "myfile.txt" that have the next content:

hola mundo
hello word

and i want work with every line

for i in `cat myfile.txt`; do echo $i; done

i hope this give me

hola mundo
hello word

firts one line, then the other, but get

hola
mundo
hello
word

as I can demanding results until newline instead of each space?

ty all


回答1:


That's better

cat myfile.txt | while read line; do
    echo "$line"
done

or even better (doesn't launch other processes such as a subshell and cat):

while read line; do
    echo "$line"
done < myfile.txt

If you prefer oneliners, it's obviously

while read line; do echo "$line"; done < myfile.txt


来源:https://stackoverflow.com/questions/9559582/echo-from-lines-of-a-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!