How do I find files that do not end with a newline/linefeed?

后端 未结 12 1249
广开言路
广开言路 2021-02-01 03:45

How can I list normal text (.txt) filenames, that don\'t end with a newline?

e.g.: list (output) this filename:

$ cat a.txt
asdfasdlsad4rand         


        
12条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-01 04:10

    Give this a try:

    find . -type f -exec sh -c '[ -z "$(sed -n "\$p" "$1")" ]' _ {} \; -print
    

    It will print filenames of files that end with a blank line. To print files that don't end in a blank line change the -z to -n.

提交回复
热议问题