从文件行中回显 [英] echo from lines of a file
本文介绍了从文件行中回显的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文件"myfile.txt",其中包含下一个内容:
i have a file "myfile.txt" that have the next content:
hola mundo
hello word
我想处理每一行
for i in `cat myfile.txt`; do echo $i; done
我希望这能给我
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?
全部
推荐答案
那更好
cat myfile.txt | while read line; do
echo "$line"
done
甚至更好(不会启动其他进程,例如subshell和cat
):
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
这篇关于从文件行中回显的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文