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

后端 未结 12 1433
广开言路
广开言路 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 example works for me on OSX (many of the above solutions did not)

    for file in `find . -name "*.java"`
    do
      result=`od -An -tc -j $(( $(ls -l $file  | awk '{print $5}') - 1 )) $file`
      last_char=`echo $result | sed 's/ *//'`
      if [ "$last_char" != "\n" ]
      then
        #echo "Last char is .$last_char."
        echo $file
      fi
    done
    

提交回复
热议问题