SatisfyMyStruggles has asked for the wisdom of the Perl Monks concerning the following question:

I need the following sed line escape in a perl script. From the commandline of bash, it works

For Example, need this sed line escape

sed -n -e /log-passed/,/log-end/p' /var/log/app1/$file

My attempt

'sed -n -e \'\/log-passed\/\,\/log-end\/p\' /var/log/app1/$file'

Replies are listed 'Best First'.
Re: Quating sed string in perl
by choroba (Cardinal) on Jun 05, 2013 at 13:57 UTC
    Your original sed line is missing a quote. If you want to call the same line through system, you have to quote it, but there is no need to quote the slashes or commas. Another problem is the variable $file: if it is a Perl variable, you should not put it into signle quotes, as they do not interpolate variables, but doulbe quotes do. If it is a shell variable, make sure it exists in the subshell started by system.
    system "sed -n -e '/log-passed/,/log-end/p' /var/log/app1/$file"; # Pe +rl variable

    Update: It is still a mystery why you cannot let Perl do all the work:

    open my $FH, '<', "/var/log/app1/$file" or die $!; while (<$FH>) { print if /log-passed/ .. /log-end/; }
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      It is probably because Perl's flip-flop operator is a greater mystery to people than sed.

        Understandable. Comma versus two dots!
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Thanks for the suggestion

      its now working and thanks for understanding the question and fixing this problem

      thanks but your perl code does not work on this file. It prints the whole file, I'm only able to get it to work in sed

Re: Quating sed string in perl
by Corion (Patriarch) on Jun 05, 2013 at 13:52 UTC

    What is your question?

    Where does your attempt fail for you?

    Did you mean to convert the sed invocation to Perl? See s2p maybe for a rough draft.

Re: Quating sed string in perl
by Anonymous Monk on Jun 05, 2013 at 13:54 UTC