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

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

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

        Hi , yeah I have tried removing all the '\' before the '$' But still the same..No matched pattern stored in result1.txt Thanks,