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

后端 未结 12 1432
广开言路
广开言路 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:16

    This is kludgy; someone surely can do better:

    for f in `find . -name '*.txt' -type f`; do
        if test `tail -c 1 "$f" | od -c | head -n 1 | tail -c 3` != \\n; then
            echo $f;
        fi
    done
    

    N.B. this answers the question in the title, which is different from the question in the body (which is looking for files that end with \n\n I think).

提交回复
热议问题