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

Hi, Thanks for the Help ,yes,It's output from shell. I've tried using shell_escape, as below,
perl -pi -e shell_escape('s#\Q(.*)\$/\',\$lines,\$matches))10.(.*)\$/ +\',\$lines,\$matches))(.*)\$/\',\$lines,\$matches))# #gi') result.tx +t > result1.txt
but got the same erroe .. Unmatched '. Whether I have used the shell_escape correctly or not.. Thanks,

Replies are listed 'Best First'.
Re^3: Delete a line from the file
by ikegami (Patriarch) on Jul 16, 2008 at 22:26 UTC
    \' doesn't work in single-quoted literals in bourne shell.
    $ echo 'foo\'bar' > <- waits for closing '

    Fixes:

    $ echo foo\'bar foo'bar $ echo "foo'bar" foo'bar $ echo 'foo'\''bar' foo'bar $ echo 'foo'"'"'bar' foo'bar
Re^3: Delete a line from the file
by NetWallah (Canon) on Jul 16, 2008 at 22:35 UTC
    From the bash manual:
    A single quote may not occur between single quotes, even when preceded by a backslash.
    Hence - my previous suggestion is invalid - there is no "escaping" inside a single-quote.

    Here is a shell trick to try:

    '"'"'
    Replace all perl-directed single quotes with that, and it should work.

    Extremely ugly, though. Here is how it works:
    It starts in single quotes, and which you want a single quote you come out, go into double quotation to quote a single quote, then come out of double quotation, to go back into single quotes again.

    Using this trick, your command passes the shell's syntax:

    perl -pi -e 's#\Q(.*)\$/'"'"',\$lines,\$matches))10.(.*)\$/'"'"',\$li +nes,\$matches))(.*)\$/'"'"',\$lines,\$matches))# #gi' result.txt > re +sult1.txt -- Output (from perl - bash is happy!!!) -- Can't open result.txt: No such file or directory.
    Update: I just noticed that my shell trick is identical to ikegami's (++) last example.

         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

      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
        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