加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

Linux – 检查文件末尾是否有换行符

发布时间:2020-12-13 19:23:26 所属栏目:Linux 来源:网络整理
导读:参见英文答案 How to detect file ends in newline?????????????????????????????????????7个 我有两个文件,一个有换行,一个没有: 文件:text_without_newline $root@kali:/home#cat text_without_newlineThis is a TestfileThis file does not contain a n

参见英文答案 > How to detect file ends in newline?????????????????????????????????????7个
我有两个文件,一个有换行,一个没有:

文件:text_without_newline

$root@kali:/home#cat text_without_newline
This is a Testfile
This file does not contain a newline at the end
$root@kali:/home#

文件:text_with_newline

$root@kali:/home#cat text_with_newline
This is a Testfile
This file does contain a newline at the end

$root@kali:/home#

是否有命令或函数来检查文件末尾是否有换行符?
我已经找到了this解决方案,但它对我不起作用. (编辑:IGNORE:使用preg_match和PHP的解决方案也可以.)

最佳答案
只需输入:

cat -e nameofyourfile

如果有换行符,则以$符号结尾.
如果没有,它将以%符号结束.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读