In debugging, I use a lot of 'print' and commenting out it with '#print'. How can I use grep to find the line without '#' before 'print'?
# print <- not detect
#print <- not detect
abc # print <-- not detect
print <- detect
|
In debugging, I use a lot of 'print' and commenting out it with '#print'. How can I use grep to find the line without '#' before 'print'?
|
||||
|
Classic solution:
|
|||||||||
|
|
The easiest approach is probably going to be to use two
With the file
That works for all of your examples. Which is probably good enough, but as manatwork and I point out in comments, its going to be very difficult to defeat all the edge cases with |
|||
|
|
I'm still learning but wouldn't the ff work as well?
|
||||
|
|
foo # bar print? – derobert Mar 13 at 15:37print '#';,print ''; # here we print,str='#'; printorstr='# print'? There is probably no 100% safe expression without partially rebuilding the language's parser. – manatwork Mar 13 at 15:38grep '^[^#]*\bprint\b' input. – manatwork Mar 13 at 15:52