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


In reply to Re: searching for string & number by prasadbabu
in thread searching for string & number.. by jaggu_bg

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.