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

find string in file

by gfarhat (Novice)
on Mar 31, 2008 at 09:43 UTC ( [id://677483]=perlquestion: print w/replies, xml ) Need Help??

gfarhat has asked for the wisdom of the Perl Monks concerning the following question:

I want to search in a file for every occurence of the word

Version followed by 0 or more whitespace and then the

character '='

Is there anyway to do it ?

Replies are listed 'Best First'.
Re: find string in file
by apl (Monsignor) on Mar 31, 2008 at 12:04 UTC
Re: find string in file
by poolpi (Hermit) on Mar 31, 2008 at 10:18 UTC

    Version followed by 0 or more whitespace : then *

    perl -ne 'print if /version [ ]* = /xi' myFile



    PooLpi

    'Ebry haffa hoe hab im tik a bush'. Jamaican proverb
Re: find string in file
by hipowls (Curate) on Mar 31, 2008 at 09:50 UTC

    perl -ne'print if /Version +=/' file_name

    perl -ne'print if /Version\s*=/' file_name

    Updated: Thanks for the corrections;-)

      perl -ne'print if /Version\s+=/' file_name
      The character class \s contains all forms of whitespace (such as tabs, ...).

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

        ... and both of you failed to notice that "0 or more" translates to *, not + ;-).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-18 22:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found