441 users online (0 members and 441 guests)  


  Results 1 to 6 of 6

Related

  1. finding 2 same letters in a row    Forum: CGI Perl Forum
    Replies: 0
  2. Simple Pattern Matching help    Forum: CGI Perl Forum
    Replies: 3
  3. Pattern Matching    Forum: CGI Perl Forum
    Replies: 1
  4. Need help finding this script    Forum: Website Scripts Forum
    Replies: 4
  1. #1
    ramki067's Avatar
    New User

    Status
    Offline
    Join Date
    Oct 2007
    Posts
    22

    Question Problems finding a pattern in a file. Please help.

    Hi,
    I need to search a pattern in each line of a file and if that pattern found then it should extract that complete line from the file and write it to another file. I've written the code but it not working!Please help. $Data is getting the data. $pattern is present in that file which i checked it out manually.Is my searching correct?

    Code:
    $handle = fopen($Filename, 'r');
    $File1 = "Automation_streams.txt";
    $Handle1 = fopen($File1, 'w');
    $d=0;
    
    while(!feof($handle))
    { 
        $Data = fgets($handle,1024);
        $pattern = $stream_names[$d];
        if(preg_match($pattern,$Data)!=0)
        {
            echo "Matched data is $Data<br>";
            fwrite($Handle1,$Data);
            $d++;
            print "<p>";
        }
        
    }
    Thanks,
    Ramki.

  2. #2
    vinyl-junkie's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    721

    Re: Problems finding a pattern in a file. Please help.

    What isn't working? Are you getting an error? If so, what error? You need to give us a little more detail on your problem.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more

  3. #3
    ramki067's Avatar
    New User

    Status
    Offline
    Join Date
    Oct 2007
    Posts
    22

    Re: Problems finding a pattern in a file. Please help.

    Quote Originally Posted by vinyl-junkie View Post
    What isn't working? Are you getting an error? If so, what error? You need to give us a little more detail on your problem.

    yeah i'm getting an error as below:

    Code:
    Warning: preg_match() [function.preg-match on line ]: Delimiter must not  be alphanumeric or backslash in C:\Program Files\Apache  Group\Apache2\htdocs\selected_streams.php83
    Last edited by HTML; 02-29-2008 at 11:12 AM.

  4. #4
    vinyl-junkie's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    721

    Re: Problems finding a pattern in a file. Please help.

    So what is the value of the regular expression you're trying to use? If you don't know, put an echo statement in your code so you can see it.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more

  5. #5
    ramki067's Avatar
    New User

    Status
    Offline
    Join Date
    Oct 2007
    Posts
    22

    Re: Problems finding a pattern in a file. Please help.

    Quote Originally Posted by vinyl-junkie View Post
    So what is the value of the regular expression you're trying to use? If you don't know, put an echo statement in your code so you can see it.

    It contains names like these..

    Code:
    "test1_WMA_40_v2_128kbps_48kHz_2"

    and the file contains these type of names as below:

    Code:
    settop decode -audio 0x1 -mpeg_type ASF -audio_type 0x86 /wma/L2/WMA_V4.0/test1_WMA_40_v2_128kbps_48kHz_2.asf    test1_WMA_40_v2_128kbps_48kHz_2    C:\Audio_Regress\recorded_files    90    48000

  6. #6
    vinyl-junkie's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    721

    Re: Problems finding a pattern in a file. Please help.

    You need a delimiter at the beginning and end of your expression. The dlimiter is typically a forward slash. So, for example, you mentioned you are looking for the string:

    Code:
    "test1_WMA_40_v2_128kbps_48kHz_2"
    I'm not sure if it has quotes around it in the text you're searching for it, but to delimit that text with the quotes included, you would do it like so:

    Code:
    /"test1_WMA_40_v2_128kbps_48kHz_2"/
    In your code then, you would append a forward slash to both the beginning and end of your variable called $pattern.

    Hope this helps.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more



Tags for this Thread