Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: can anyone help with to write this script???

by prasadbabu (Prior)
on Nov 27, 2008 at 05:45 UTC ( #726302=note: print w/replies, xml ) Need Help??

in reply to searching for number & string....

Hi jaggu_bg,

Welcome to the Monastery! Make yourself at home.. Post the questions in Seekers of Perl Wisdom.

You have to go through open, perlsyn, perlop and perlre to accomplish your job.

#open the file in read mode - refer open documentation #search the PID and string using regex -refer regex documentation #check the condition - refer Perl operator documentation #open the file in write mode to save in new file - refer open document +ation #write the result - refer Perl Syntax documentation


Replies are listed 'Best First'.
Re^2: can anyone help with to write this script???
by jaggu_bg (Initiate) on Nov 27, 2008 at 06:14 UTC
    i ve this program searching for PID but i am unable to add a atring lso in that... can u help out???
    use Getopt::Std; getopts('hDp:f:sb:e:q:t:jl'); if($Getopt::Std::opt_f) {$sFile = $Getopt::Std::opt_f;} if($Getopt::Std::opt_p) {$iPid = $Getopt::Std::opt_p;} if($Getopt::Std::opt_q) {$sOutFile = $Getopt::Std::opt_q;} if($Getopt::Std::opt_c) {$iStr = $Getopt::Std::opt_c;} my $sAppNameString = "[c,C][m,M]"; my $sStartString = ".?[DWEM]"; my $sAppPidString = ".*\\s+$sAppNameString:(\\d+\\.?\\d*)\\s+.*"; my $sAppString = "$sStartString$sAppPidString"; open(HFILE, "< $sFile") or die ("Failed to open $sFile"); $hFile = *HFILE; print ("Processing file: \"$sFile\"\n"); #Splitting the log file per pid if ($Getopt::Std::opt_s) { seek($hFile,0,0); while (<$hFile>) { if (m/$sAppString/) { $iPidTmp = $1; } if(($iPid != 0) && ($iPid != $iPidTmp)) { next; } $hOutputFile = $hFiles{$iPidTmp}; if($hOutputFile) { print $hOutputFile "$_"; }else{ print ("PID = $iPidTmp\n"); open( HPIDFILE.$iPidTmp, ">$sOutFile.$iPidTmp" ) or die ("Failed to open $sOutputFile.$iPidTmp"); $hFiles{$iPidTmp} = *HPIDFILE.$iPidTmp; $hOutputFile = $hFiles{$iPidTmp}; print $hOutputFile "$_"; } } }

      Oww, my eyes! x-{

      On the page linked by prasadbabu, after going through 3 more clicks (Perl Monks Site FAQ - PerlMonks FAQ - "Posting on PerlMonks"), you will see the links about how to format your post and choose a sensible title. Which is to say ...

      Please add code tags: <c> before the start of your code on its own line, and </c> after the end of the tag on its own line. And, please change the title of your post to "Searching for a number in a file" or similar.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2020-05-30 11:52 GMT
Find Nodes?
    Voting Booth?
    If programming languages were movie genres, Perl would be:

    Results (171 votes). Check out past polls.