in reply to Delete a line from the file

Looks like your shell (bash ?) is reporting the error.

Since you are passing a string to perl that is supposed to be enclosed in single-quotes, you need to use SHELL-ESCAPE characters if you want to use single-quote inside that string. Or, use double-quotes.

Shell-escape is usually a backslash, similar to perl, so you need to b aware as to which backslash gets eaten by the shell, and which one is for perl's consumption.

Update: Ignore this - While the diagnosis is correct, the proposed solution is wrong. Better information in 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

Replies are listed 'Best First'.
Re^2: Delete a line from the file
by ajd335 (Novice) on Jul 16, 2008 at 22:21 UTC
    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,
      \' 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
      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