Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: searching for string & number

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


in reply to searching for string & number..

Hi jaggu_bg,

After seeing your code with some assumptions, I have created a below script. You have to be very specific with your input and required output, so that we can give the answer without any assumptions.

I have taken input file and input string as input parameters and created the output in output.txt file.

use strict; use warnings; my $input_file = $ARGV[0]; #input file name my $input_pid = $ARGV[1]; #input file name my $input_string = $ARGV[2]; #input string to be searched in the matc +hed string print "Usage: test.pl <input file name> <input process id> <input file + string>" if (@ARGV != 3); open (my $hfile, '<', "$input_file") || die("Unable to open the file $ +input_file\n"); open (my $ofile, '>', "output.txt") || die("Unable to open the file ou +tput.txt\n"); while (<$hfile>){ #read the file line by line my $line = $_; if ($line =~ /[DWEM]\s+.*?\s+(?:c|cm|M)\:($input_pid)\s+([^\.]+\.c +)/s) { my $c_file = $2; my $pid = $1; if($input_string eq $c_file){ #check with input string and i +f matches print $ofile "$line\n"; #write the output in a output file } } } Command Line: ------------- >perl test.pl a.txt 10570 'cm_child.c' File output.txt: ---------------- PID:10570 C File:cm_child

Updated:Based on the input given by OP in private message and below reply

Prasad


Comment on Re: searching for string & number
Download Code
Re^2: searching for string & number
by jaggu_bg (Initiate) on Nov 27, 2008 at 09:22 UTC
    hi, i am new ... sorry for the in adequate data. actually i have to enter a pid number and a string. like 10570 and fm_cust_validate_customer.c. in output i have to get all the lines which matches this two . as u can see in log file it starts with E,D,M,W. i need all lines from one E to other E or D anything which matches pid number & the string.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (15)
As of 2015-07-06 12:13 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 (74 votes), past polls