Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^3: How do i search and extract commented lines from a file using perl?

by aaron_baugher (Curate)
on Jun 26, 2015 at 20:23 UTC ( #1132227=note: print w/replies, xml ) Need Help??


in reply to Re^2: How do i search and extract commented lines from a file using perl?
in thread How do i search and extract commented lines from a file using perl?

If I understand the problem, you want to find all files beneath a directory which contain a certain string, except ignoring the string when it falls in a comment block. Here's a solution that uses perl:

find . -type f -print0 | while read -d $'\0' f; do if perl -0777pe 's| +/\*.*?\*/||gs' $f | grep certain_string >/dev/null; then echo $f; fi +; done

Aaron B.
Available for small or large Perl jobs and *nix system administration; see my home node.

  • Comment on Re^3: How do i search and extract commented lines from a file using perl?
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1132227]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2020-05-29 18:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (170 votes). Check out past polls.

    Notices?