r/linux_programming • • Jun 14 '19

Understanding about grep implementation

Hi everyone, so I was reading about grep command in my free time and I got to wondering that how does grep technically implements highlighting of matched strings in text? Like I grep for abc in xyz file then it highlights all the occurrences of abc in stdout. Any idea how it is achieved?

6 Upvotes

10 comments sorted by

View all comments

Show parent comment

1

u/nderflow Jun 17 '19

GNU grep's trick is not dividing the input into lines before processing it, and only calculating the line number when there is a hit.