Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

How to find that a line "genman.py" exists in a python file

by Anonymous Monk
on Apr 01, 2012 at 17:20 UTC ( #962898=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to find if a line "genman.py" exists in a file "C:\python.py".Can someone suggest how can I do that?

use strict; use warnings; my $gen_build_man = C:\python.py open my $GENMAN, '<', "$gen_build_man" or die "could not open $gen_bui +ld_man - $!"; while (<$GENMAN>) { #check if it has the line "genman.py" }

Comment on How to find that a line "genman.py" exists in a python file
Download Code
Replies are listed 'Best First'.
Re: How to find that a line "genman.py" exists in a python file
by stevieb (Deacon) on Apr 01, 2012 at 17:35 UTC
    use strict; use warnings; my $gen_build_man = C:\python.py open my $GENMAN, '<', "$gen_build_man" or die "could not open $gen_bui +ld_man - $!"; while ( my $line = <$GENMAN> ){ print "I have the line!" if $line =~ /genman\.py/; }

      I actually want to print it if the line is *not* there

        use strict; use warnings; my $gen_build_man = C:\python.py open my $GENMAN, '<', "$gen_build_man" or die "could not open $gen_bui +ld_man - $!"; my $found = 0; while ( my $line = <$GENMAN> ){ $found = 1 if $line =~ /genman\.pl/; } print "genman.pl not found in the file" if ! $found;
Re: How to find that a line "genman.py" exists in a python file
by JavaFan (Canon) on Apr 01, 2012 at 23:34 UTC
    No need for Perl.
    $ grep 'genman\.py' C:\python.py
    Or, to print all non-matching lines:
    $ grep -v 'genman\.py' C:\python.py
      or, if the OP happens to be on Windows, findstr will do the same thing:
      findstr /c:"genman.py" C:\python.py findstr /v /c:"genman.py" C:\python.py

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2015-07-08 00:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls