Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

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]
[davido]: I am not finding closing STDIN to be an adequate means of making getlogin return undef.
[Corion]: Maybe doing a double-fork (daemonizing) can make go that information away, but maybe not
[Corion]: But I think my knowledge of unix/Linux datastructures is several decades out of date, so I don't really know what information it keeps on processes
[oiskuu]: The useful bits that relate to your process can be found under /proc/self. What information are you thinking of? Tty name?
[tye]: I just daemonized and getlogin() still knew who I had been.
[tye]: perhaps loginuid ? Not that I concede that something not being in /proc means it is not useful.

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2017-06-23 19:36 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (554 votes). Check out past polls.