bash while循环删除文本文件的最后一行 [英] bash while loop drops last line of text file

查看:83
本文介绍了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屋!

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