"; if (isset($_GET['endfind'])) $endfind=str_replace("+"," ",urldecode($_GET['endfind'])); $newlabelfindstart=' label="'; if (isset($_GET['newlabelfindstart'])) $newlabelfindstart=str_replace("+"," ",urldecode($_GET['newlabelfindstart'])); $newlabelfindend='"'; if (isset($_GET['newlabelfindend'])) $newlabelfindend=str_replace("+"," ",urldecode($_GET['newlabelfindend'])); $oldlabelfindstart=' old_label="'; if (isset($_GET['oldlabelfindstart'])) $oldlabelfindstart=str_replace("+"," ",urldecode($_GET['oldlabelfindstart'])); $oldlabelfindend='"'; if (isset($_GET['oldlabelfindend'])) $oldlabelfindend=str_replace("+"," ",urldecode($_GET['oldlabelfindend'])); $labelthis=' uci="'; if (isset($_GET['labelthis'])) $labelthis=str_replace("+"," ",urldecode($_GET['labelthis'])); $labelthistwo='"'; if (isset($_GET['labelthistwo'])) $labelthistwo=str_replace("+"," ",urldecode($_GET['labelthistwo'])); $findthis=' role="paragraph"'; if (isset($_GET['findthis'])) $findthis=str_replace("+"," ",urldecode($_GET['findthis'])); $findthistwo=''; if (isset($_GET['findthistwo'])) $findthistwo=str_replace("+"," ",urldecode($_GET['findthistwo'])); $findthisthree=''; if (isset($_GET['findthisthree'])) $findthisthree=str_replace("+"," ",urldecode($_GET['findthisthree'])); $titlethis='>'; if (isset($_GET['titlethis'])) $titlethis=str_replace("+"," ",urldecode($_GET['titlethis'])); $titlethistwo=''; if (isset($_GET['titlethistwo'])) $titlethistwo=str_replace("+"," ",urldecode($_GET['titlethistwo'])); $csvname="global_substitution.csv"; if (isset($_GET['csvname'])) $csvname=str_replace("+"," ",urldecode($_GET['csvname'])); $halfwayprefix=""; if (isset($_GET['halfwayprefix'])) $halfwayprefix=str_replace(",","",str_replace("+"," ",urldecode($_GET['halfwayprefix']))); $kshname="global_substitution.ksh"; if (isset($_GET['kshname'])) $kshname=str_replace("+"," ",urldecode($_GET['kshname'])); $doksh=""; // "ksh -x global_substitution.ksh"; if (isset($_GET['doksh'])) $doksh=str_replace("+"," ",urldecode($_GET['doksh'])); $followup=""; if (isset($_GET['followup'])) $followup=str_replace(">","",str_replace("<","",str_replace(" 1) { $uext=strtoupper("." . $extis[-1 + sizeof($extis)]); $lext=strtolower("." . $extis[-1 + sizeof($extis)]); if ($lext == ".xxx") { $lalt=".xzz"; $ualt=".XZZ"; } else { $lalt=substr($lext,0,2) . "xx"; $ualt=substr($uext,0,2) . "XX"; } } if ($halfwayprefix != "" && file_exists($csvname) && file_exists($indexfilecalled) && !file_exists($kshname)) { // jobs where supplied with index file and intermediate CSV and a "halfway prefix" to search for in CSV file, but no KSH file yet $csvcont=@file_get_contents($csvname); $csvlines=explode("\n",$csvcont); $oldresults=""; if ($doksh != "") { $results="
" . basename($indexfilecalled) . " changes on " . gmdate("l jS \of F Y h:i:s A") . " GMT below ..."; $oldresults="
" . basename($indexfilecalled) . " below ...
" . str_replace("<","<",str_replace(">",">",file_get_contents($indexfilecalled))) . "
... New Versus Old ..." . basename($indexfilecalled . "_original_backup") . " below ...
" . str_replace("<","<",str_replace(">",">",file_get_contents($indexfilecalled))) . "

"; } for ($icsvlines=0; $icsvlines" . $oldfielddata . "", $oldresults); if ($newfielddata != "") $results=str_replace($oldfielddata,"" . $newfielddata . "", $results); } } $kshout.=$delim . "cat " . $indexfilecalled . " | sed '/\\" . str_replace("]","\\]",$oldfielddata) . "/s//\\" . str_replace("]","\\]",$newfielddata) . "/g' > " . str_replace($uext,$ualt,str_replace($lext,$lalt,$indexfilecalled)) . " ; rm -f " . $indexfilecalled . " ; cat " . str_replace($uext,$ualt,str_replace($lext,$lalt,$indexfilecalled)) . " > " . $indexfilecalled . " ; "; $delim="\n"; } } if ($delim != "") { rename($csvname, $csvname . "_original_backup"); file_put_contents($kshname, $kshout); if ($doksh != "") { if (!file_exists($indexfilecalled . "_original_backup")) copy($indexfilecalled, $indexfilecalled . "_original_backup"); $results.=$oldresults; file_put_contents("COM_.htm", "
" . explode("",explode("",$results)[0])[-1 + sizeof(explode("",explode("",$results)[0]))] . "
"); exec($doksh); sleep(2); $results.="
" . basename($indexfilecalled) . " " . gmdate("l jS \of F Y h:i:s A") . " GMT below ...
" . basename($indexfilecalled) . " below ...
... New Versus Old ..." . basename($indexfilecalled . "_original_backup") . " below ...

"; } } } else if (isset($_GET['filespec'])) { // jobs with no CSV yet $topresults=""; $oldresults=""; $newresults=""; if ($doksh != "") { $newresults.="
" . basename($indexfilecalled) . " changes on " . gmdate("l jS \of F Y h:i:s A") . " GMT below ..."; $oldresults.="
" . basename($indexfilecalled) . " below ...
" . str_replace("<","<",str_replace(">",">",file_get_contents($indexfilecalled))) . "
... New Versus Old ..." . basename($indexfilecalled . "_original_backup") . " below ...
" . str_replace("<","<",str_replace(">",">",file_get_contents($indexfilecalled))) . "

"; } foreach (glob($filespec) as $filename) { $cont=@file_get_contents($filename); $chapteruci=""; if ($labelthis != "" && $labelthistwo != "") { if (strpos($cont,$labelthis) !== false) { $chapteruci=explode($labelthistwo,explode($labelthis, $cont)[1])[0]; } } $sections=explode($startfind, $cont); for ($i=1; $i>",">",str_replace("")))),explode(trim($thebit), $cont)[1])[0], $titlethistwo) !== false && strpos(explode(str_replace(">>",">",str_replace("")))),explode(trim($thebit), $cont)[1])[0], $titlethis) !== false) { $subtitle=explode($titlethis,explode($titlethistwo,str_replace("","",str_replace("","",str_replace("","",str_replace("","",explode(trim($thebit), $cont)[1])))))[0])[-1 + sizeof(explode($titlethis,explode($titlethistwo,str_replace("","",str_replace("","",str_replace("","",str_replace("","",explode(trim($thebit), $cont)[1])))))[0]))]; } } } catch (Exception $ee) { $subtitle=""; } } $csvout.=$delim . $chapteruci . "," . explode($oldlabelfindend,explode($oldlabelfindstart, $thebit)[1])[0] . ",," . explode($newlabelfindend,explode($newlabelfindstart, $thebit)[1])[0] . "," . $subtitle; if ($doksh != "") { if (explode($oldlabelfindend,explode($oldlabelfindstart, $thebit)[1])[0] != "") { $oldresults=str_replace(explode($oldlabelfindend,explode($oldlabelfindstart, $thebit)[1])[0],"" . explode($oldlabelfindend,explode($oldlabelfindstart, $thebit)[1])[0] . "", $oldresults); if (explode($newlabelfindend,explode($newlabelfindstart, $thebit)[1])[0] != "") $newresults=str_replace(explode($oldlabelfindend,explode($oldlabelfindstart, $thebit)[1])[0],"" . explode($newlabelfindend,explode($newlabelfindstart, $thebit)[1])[0] . "", $newresults); } } $kshout.=$delim . "cat " . $indexfilecalled . " | sed '/\\" . str_replace("]","\\]",explode($oldlabelfindend,explode($oldlabelfindstart, $thebit)[1])[0]) . "/s//\\" . str_replace("]","\\]",explode($newlabelfindend,explode($newlabelfindstart, $thebit)[1])[0]) . "/g' > " . str_replace($uext,$ualt,str_replace($lext,$lalt,$indexfilecalled)) . " ; rm -f " . $indexfilecalled . " ; cat " . str_replace($uext,$ualt,str_replace($lext,$lalt,$indexfilecalled)) . " > " . $indexfilecalled . " ; "; $delim="\n"; } } else if ($objections == "" && strpos($thebit, $newlabelfindstart) !== false && strpos($thebit, $newlabelfindstart) !== false && ($findthis == '' || strpos($thebit, $findthis) !== false) && ($findthistwo == '' || strpos($thebit, $findthistwo) !== false) && ($findthisthree == '' || strpos($thebit, $findthisthree) === false)) { //echo "it happens"; //exit; if (str_replace("]","\\]",explode($newlabelfindend,explode($newlabelfindstart, $thebit)[1])[0]) != "") { //echo "thebit=" . trim($thebit) . " afters=" . str_replace(">",">",str_replace("<","<",explode(trim($thebit), $cont)[1])) . " thisbits[1]=" . str_replace("<","<",str_replace(">",">",$thisbits[1])); //exit; $subtitle=""; if ($titlethis != "" && $titlethistwo != "") { try { if (strpos($cont, trim($thebit)) !== false) { if (strpos(explode(str_replace(">>",">",str_replace("")))),explode(trim($thebit), $cont)[1])[0], $titlethistwo) !== false && strpos(explode(str_replace(">>",">",str_replace("")))),explode(trim($thebit), $cont)[1])[0], $titlethis) !== false) { $subtitle=explode($titlethis,explode($titlethistwo,str_replace("","",str_replace("","",str_replace("","",str_replace("","",explode(trim($thebit), $cont)[1])))))[0])[-1 + sizeof(explode($titlethis,explode($titlethistwo,str_replace("","",str_replace("","",str_replace("","",str_replace("","",explode(trim($thebit), $cont)[1])))))[0]))]; } } } catch (Exception $ee) { $subtitle=""; } } $csvout.=$delim . $chapteruci . ",,," . explode($newlabelfindend,explode($newlabelfindstart, $thebit)[1])[0] . "," . $subtitle; if ($doksh != "") { if (explode($newlabelfindend,explode($newlabelfindstart, $thebit)[1])[0] != "") { $oldresults=str_replace(explode($newlabelfindend,explode($newlabelfindstart, $thebit)[1])[0],"" . explode($newlabelfindend,explode($newlabelfindstart, $thebit)[1])[0] . "", $oldresults); if (explode($newlabelfindend,explode($newlabelfindstart, $thebit)[1])[0] != "") $newresults=str_replace(explode($newlabelfindend,explode($newlabelfindstart, $thebit)[1])[0],"" . explode($newlabelfindend,explode($newlabelfindstart, $thebit)[1])[0] . "", $newresults); } } $kshout.=$delim . "cat " . $indexfilecalled . " | sed '/\\" . "" . "/s//\\" . str_replace("]","\\]",explode($newlabelfindend,explode($newlabelfindstart, $thebit)[1])[0]) . "/g' > " . str_replace($uext,$ualt,str_replace($lext,$lalt,$indexfilecalled)) . " ; rm -f " . $indexfilecalled . " ; cat " . str_replace($uext,$ualt,str_replace($lext,$lalt,$indexfilecalled)) . " > " . $indexfilecalled . " ; "; $delim="\n"; } } } } $topresults.=$newresults . $oldresults; if ($csvout != "") { file_put_contents($csvname, $csvout); file_put_contents($kshname, $kshout); if ($topresults != "") { file_put_contents("COM_.htm", "
" . explode("",explode("",$topresults)[0])[-1 + sizeof(explode("",explode("",$topresults)[0]))] . "
"); } if ($doksh != "") { if (!file_exists($indexfilecalled . "_original_backup")) copy($indexfilecalled, $indexfilecalled . "_original_backup"); exec($doksh); sleep(2); $results="
" . basename($indexfilecalled) . " " . gmdate("l jS \of F Y h:i:s A") . " GMT below ...
" . basename($indexfilecalled) . " below ...
... New Versus Old ..." . basename($indexfilecalled . "_original_backup") . " below ...

"; $results.=$topresults; } } } if ($followup != "" && file_exists($indexfilecalled)) { $cont=@file_get_contents($indexfilecalled); $sections=explode("", $cont); $repd=""; for ($i=0; $i",$sections[$i])[-1 + sizeof(explode("<" . $followup . ">",$sections[$i]))] . "\n"; } file_put_contents("COM_rep.txt", $repd); } ?> Global Substitution Helper - RJM Programming - September, 2017

Global Substitution Helper

  RJM Programming - September, 2017

File name for input (and output) index file (to change):

File specification for input data:
Start delimitation of tags of interest:
End delimitation of tags of interest:
New label regarding global substitutions start delimitation (but if you want both old and new finds click "both"):
New label regarding global substitutions end delimitation:
Old label regarding global substitutions start delimitation:
Old label regarding global substitutions end delimitation:
First Label (CSV first field) tag prefix:
First Label (CSV first field) tag suffix:
Find this within tag 1/3:
Find this within tag 2/3:
Do not find this within tag:
After Find Title (CSV last field) tag prefix:
After Find Title (CSV last field) tag suffix:

Output (and intermediate) CSV file name:

Halfway House Old and New Prefix (eg: [) for jobs where supplied with existant index file and existant intermediate CSV file,
but no existant Korn Shell file yet (and so for this we also recommend filling in "finalize job" below):

Output (and intermediate) Korn Shell script file name:

Optional command line to finalize job (eg. ksh -x global_substitution.ksh) ... can result in COM_.htm report:
Follow Up COM_rep.txt "sanity check" report tag report basis (eg. <olink>) ... can result in COM_rep.txt report: