Monday, May 6, 2024
 Popular · Latest · Hot · Upcoming
9
rated 0 times [  9] [ 0]  / answers: 1 / hits: 10561  / 3 Years ago, sun, may 30, 2021, 9:13:17

Is it possible, using grep, to search for instances of John Smith but exclude instances of Mr John Smith?


More From » grep

 Answers
5

This could be solved using a regular expression with negative lookbehind (which is experimentally supported in grep as pointed out by the comment from arrange):



$ grep -P '(?<!Mr )John Smith' file


Since the support is just experimental, you might want to use perl instead:



$ perl -nle 'print if /(?<!Mr )John Smith/' file

[#41499] Tuesday, June 1, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
termetalli

Total Points: 326
Total Questions: 127
Total Answers: 110

Location: Sao Tome and Principe
Member since Sat, Sep 12, 2020
4 Years ago
termetalli questions
Sat, Apr 30, 22, 17:54, 2 Years ago
Mon, Dec 6, 21, 05:24, 2 Years ago
Thu, Jun 30, 22, 00:32, 2 Years ago
Mon, Dec 19, 22, 00:15, 1 Year ago
;