bash while 循环删除文本文件的最后一行 [英] bash while loop drops last line of text file
本文介绍了bash while 循环删除文本文件的最后一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我找到这个文件时,我得到 6 行(这是一个差异文件)
when i cat this file I get 6 lines (it is a diff file)
bash-3.00$ cat /tmp/voo
18633a18634
> sashabSTP
18634a18636
> sashatSTP
21545a21548
> yheebash-3.00$
然而,当我一行一行地阅读它时,我只得到了 5 行.
however when i read it line by line i only get 5 lines.
bash-3.00$ while read line ; do echo $line ; done < /tmp/voo
18633a18634
> sashaSTP
18634a18636
> sashatSTP
21545a21548
或者这个
bash-3.00$ cat /tmp/voo | while read line ; do echo $line ; done
18633a18634
> sashabSTP
18634a18636
> sashatSTP
21545a21548
bash-3.00$
我遗漏了 while 循环中的最后一行 'yhee'.
i am missing the last line 'yhee' from the while loops.
推荐答案
注意:
21545a21548
> yheebash-3.00$
^---- no line break
您的文件不会以换行符结尾.
Your file doesn't terminate with a line break.
这篇关于bash while 循环删除文本文件的最后一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文