Skip to main content
Tweeted twitter.com/StackUnix/status/1006989739105415168
edited title
Link
ilkkachu
  • 147.9k
  • 16
  • 268
  • 441

How to make grep ignoringignore lines without trailing newline character

Source Link
dshin
  • 183
  • 1
  • 6

grep ignoring lines without trailing newline character

I'd like to grep a file for a string, but ignore any matches on lines that do not end with a trailing newline character. In other words, if the file does not end with a newline character, I'd like to ignore the last line of the file.

What is the best way to do this?

I encountered this issue in a python script that calls grep via the subprocess module to filter a large text log file before processing. The last line of the file might be mid-write, in which case I don't want to process that line.