vim line ending

vi 自动添加换行符(unix \n dos \r\n) (echo 20001 > a.txt 得到同样的结果)
vim a.txt
输入20001 :wq

php -r '$a= file_get_contents("a.txt");echo ($a[5]==="\n")?1:2;' //1
vim a.txt
:set ff=dos
:wq
php -r '$a= file_get_contents("a.txt");echo ($a[5]==="\r")?1:2;' //1
php -r '$a= file_get_contents("a.txt");echo ($a[6]==="\n")?1:2;' //1

//由于存在换行符 因此vim编辑文件的md5值与单纯内容的md5值不一致
php -r '$a=file_get_contents("a.txt");echo md5($a) !== md5(20001)?1:2;' //1

//unix shell中的md5sum也是因为同样的原因不一致
(md5sum -b a.txt) != (md5sum -b - 20001)

一些不会填加换行符的操作

echo -n 20001 > a.txt
php -r 'file_put_contents("a.txt",20001);'


links:
[url]http://stackoverflow.com/questions/1654021/how-can-i-delete-a-newline-if-it-is-the-last-character-in-a-file/1663283[/url]
[url]http://stackoverflow.com/questions/1050640/vim-disable-automatic-newline-at-end-of-file[/url]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值