On May 23, pda said:

>   <!--
>   <td>
>
>now her i want a regular expression where it has to check for the <!--
>and come to the new line and also check whether if there is a <td> in
>the given file if it finds it has to replace with a other string.
>
>this is what i tryed on the command prompt.
>
>perl -pi -e 's{^<!--\n<td>}{test}' hello.txt

This is because your file is read in line-by-line, so there's no way for
Perl to match something after the newline.  Try reading the file in all at
once:

  perl -0777 -pi -e 's{^<!--\n<td>}{test}m' hello.txt

Two things:

  -0 is for the input record separator (what separates "lines")
    setting it to 777 means "read the entire file at once; you might be
    ok using -0000, which reads "paragraphs" (text separated by 2 or more
    newlines)

  the /m modifier makes ^ match at the beginning of a string *OR* at the
    beginning of a "line" (right after a \n); it also changes $ to match
    at the end of a "line" too (right before a newline)

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
Are you a Monk?  http://www.perlmonks.com/     http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc.     http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter.         Brother #734
** I need a publisher for my book "Learning Perl's Regular Expressions" **


Reply via email to