0

'

Number found where operator expected at ./scripttemp.perl line 5, near ""sed -i -r "4" (Missing operator before 4?) String found where operator expected at ./scripttemp.perl line 5, near "}" error.txt"" (Missing operator before " error.txt"?) syntax error at ./scripttemp.perl line 5, near ""sed -i -r "4" syntax error at ./scripttemp.perl line 5, near "s/[-.*-]//g}" Execution of ./scripttemp.perl aborted due to compilation errors. '

I am getting this error running my script :

**#!/usr/bin/perl
use warnings;
use strict;
exec("sed -i -r "4{s/\{\+//; s/\+}//; s/\[-.*-]//g}" error.txt");**

Please tell me what is wrong?

  • 2
    Why are you calling sed from Perl? – Kusalananda Jun 14 at 6:59
  • Because I want to – Coolstrike Jun 14 at 8:49
1

It's your use of double quotes. You cannot use double quotes "inside" double quotes unless they are escaped. Instead you could either escape your double quotes or more preferrably alternate quotes by using single quotes instead:

#!/usr/bin/perl
use warnings;
use strict;
exec("sed -i -r '4{s/\{\+//; s/\+}//; s/\[-.*-]//g}' error.txt");
  • You may also have an issue in your regex (the unescaped "}" and "]") – jjj Jun 14 at 6:51
  • Now I am having this error : >sed: -e expresssion #1, char 9: Invalid Regular Expression – Coolstrike Jun 14 at 8:50
  • Could you provide some example error.txt lines and what exactly you are trying to make the lines look like? – jjj Jun 14 at 9:04
  • The thing is if i run : ~sed -i -r '4{s/\{\+//; s/\+}//; s/[-.*-]//g}' error.txt through linux command shell it runs perfectly but when i try to run it through perl script it gives me an error – Coolstrike Jun 14 at 9:10
  • The most basic debugging process: Reduce your script and try it, repeat till you've isolated the problem. – Ed Morton Jun 15 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.