How to use the Linux command to add php code in batches under a line of code

there are more than 10 identical stations
/ data/www/aa.com/test.php
/ data/www/bb.com/test.php
/ data/www/cc.com/test.php
I want to use the Linux command to batch modify / data/www/aa.com/test.php a certain line of the specified file $article" MODEL ("article"); add the following code

        $M->AddNewsHits(array("id"=>(int)$_GET["id"]));
        $news_info=$M->GetNewsBaseOnce(array("id"=>(int)$_GET["id"]),array("field"=>"hits"));
        echo "document.write("".$news_info["hits"]."")";

how to write with the linux shell command, there is still a better way to give up

Feb.14,2022
The

shell script has not thought of a way to deal with php for the time being.
you take the code of the / data/www/bb.com/test.php file with fgets ($fp) , and then process it into an array of $code [$num] = [.] .
then in the line you want to join, use array_splice ($code, $num, 0, $newcode) . After processing, process it into a string and rewrite it to the / data/www/bb.com/test.php file.


-sharp!/usr/bin/sh

sites=`ls /data/www`
  
for site in $sites
do
    sed -i '{line} a\ \ \ \ $M->AddNewsHits(array("id"\ =>\ (int)\ $_GET["id"]));\n\ \ \ \ $news_info\ =\ $M->GetNewsBaseOnce(array("id"\ =>\ (int)\ $_GET["id"]),\ array("field"\ =>\ "hits"));\n\ \ \ \ echo\ "document.write(\\\"".$news_info["hits"]."\\\")"' /data/www/$site/test.php
done

the script above inserts the following code after the {line} line. Note that {line} represents the number of lines, and do not leave {}. This is what happens when you replace: sed-I'10 ahhh' / path/to/file this means inserting hhh

after line 10.
Menu