in reply to Re^3: Delete a line from the file
in thread Delete a line from the file

Hey NetWallah Thanks for the help...The error is gone...But cant see any result in result1.txt .. So , may be some match is not done or so... the string in file to be removed is
(.*)$/',$lines,$matches) 10.(.*)$/',$lines,$matches) (.*)$/ +',$lines,$matches)
There are tabs in between.. Thanks

Replies are listed 'Best First'.
Re^5: Delete a line from the file
by NetWallah (Canon) on Jul 16, 2008 at 23:07 UTC
    I think you are over-escaping the shell.

    Since you are in single-quotes, attempting to escape the $ using \$ causes the $ to be interpreted literally by perl where you did not intend.

    Specifically, I think you intended perl to see "$var" , but you have a "\" preceding the $ , and that \ is passed to perl, so perl thinks you want a literal $var, instead of interpolating.

    Here is how perl currently sees your re:

    s#\Q(.*)\$/',\$lines,\$matches))10.(.*)\$/',\$lines,\$matches))(.*)\ +$/',\$lines,\$matches))# #gi
    You need to remove all attempts to escape all $'s in front of variable names.

    Update:The problem is that \Q interpolates and disallows \$ - see my response below.

         Have you been high today? I see the nuns are gay! My brother yelled to me...I love you inside Ed - Benny Lava, by Buffalax

      Hi , yeah I have tried removing all the '\' before the '$' But still the same..No matched pattern stored in result1.txt Thanks,
        This one works:
        perl -ne 'BEGIN{ $s=q ~(.*)$/'"'"',$lines,$matches) 10.(.*)$/'" +'"',$lines,$matches) (.*)$/'"'"',$lines,$matches)~};print unless +/\Q$s\E/' input.txt
        Instead of doing an in-place replace , You can redirect the output of this to the final file.

        It seems like "\Q" and the "$" symbol do not interact well when directly in a RE.

        If you put the "$" symbols outside \Q..\E , it seems to work.

        Here is the quote from http://www.perl.com/doc/manual/html/pod/perlre.html

        You cannot include a literal $ or @ within a \Q sequence. An unescaped $ or @ interpolates the corresponding variable, while escaping will cause the literal string \$ to be matched. You'll need to write something like m/\Quser\E\@\Qhost/.

        So, this one works too ..(But it sure is UGLY!)

        perl -ne 'print unless m~\Q(.*)\E\$/'"'"',\$lines,\$matches\Q) + 10.(.*)\E\$/'"'"',\$lines,\$matches\Q) (.*)\E\$/'"'"',\$lines,\$ +matches\)~x' input.txt

             Have you been high today? I see the nuns are gay! My brother yelled to me...I love you inside Ed - Benny Lava, by Buffalax