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

Use pcregrep, a Perl Compatible Regular Expressions version of grep which supports a multiline mode using -M flag that can be used to match (or not match) if the last line had a newline:

pcregrep -LMr '\n\Z' .

In the above example we are saying to search recursively (-r) in current directory (.) listing files that don’t match (-L) our multiline (-M) regex that looks for a newline at the end of a file ('\n\Z')

Changing -L to -l would list the files that do have newlines in them.

pcregrep can be installed on MacOS with the homebrew pcre package: brew install pcre

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)