Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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

by prasadbabu (Prior)
on Nov 27, 2008 at 05:45 UTC ( [id://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

Prasad

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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-25 13:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found