Search code examples
phpregexbashsedshell-exec

Sed doesnt work with shell_Exec()


I have a file that looks like this:

#EXTM3U
#EXTINF:-1 tvg-id="A&E [Brazil]" tvg-name="A&E **" tvg-logo="http://url/2dhy3yl" group-title="FILMES & SERIES",A&E **
http://url/live/Enrico/321/6660.ts
#EXTINF:-1 tvg-id="A E [Brazil]" tvg-name="AeE" tvg-logo="http://url/2dhy3yl" group-title="FILMES & SERIES",AeE
http://url/live/Enrico/321/232.ts
#EXTINF:-1 tvg-id="A&E [Brazil]" tvg-name="BR: AeE *" tvg-logo="http://URL/2dhy3yl" group-title="FILMES & SERIES",AeE *
http://url/live/Enrico/321/5171.ts
#EXTINF:-1 tvg-id="A&E HD [Brazil]" tvg-name="A&E HD" tvg-logo="http://URL/2dhy3yl$
http://url/live/Enrico/321/4057.ts

I want to remove everything that contains ** (double asterisk), single asteris followed by double quotes (*") and the (tvg-name="BR:) string. I managed to do it with sed but it doesnt run on php shell_exec();

Here is my sed code

sed -i '/\*\*/d' ./filename
sed -i '/tvg-name="BR:/d' ./filename
sed -i '/\*"/d' ./filename

How do i execute this with shell_exec or any other php function? Thank you!


Solution

  • For PHP, assuming the contents of the file have been gathered into the $sContents parameter:

    $sContents = preg_replace('/(\*\*|\*"|"BR:)/', '', $sContents);
    

    And for sed:

    sed -e 's/\*\*//' -e 's/\*"//' -e 's/"BR://' filename
    

    sed is very old, and Perl is much more powerful, and uses the same regular expression logic as PHP:

    perl -pe 's/(\*\*|\*"|"BR:)//' filename