#!/bin/ksh echo 'Files of a pattern and the same size replaced by a new version ...' echo '' echo 'Path to new version of file eg. ./index.php' read index if [ -f "$index" ]; then echo '' echo 'Must find this string eg. foreach (glob(' read findstring if [ ! -z "$findstring" ]; then echo '' echo 'Must be this many bytes long eg. 7006 or 11472 or 18330 or 18570 or 23882 or 26649 or 29451 or 38792' read thismany if [ ! -z "$thismany" ]; then echo '' echo 'Path to files to be replaced by this new version of file eg. /a/path/to/root/directory/of/interest/' read path if [ -d "$path" ]; then echo '' echo 'Filespec or filename of files to be replaced by a new version of file eg. index.php' read filespec if [ ! -z "$filespec" ]; then echo '' echo 'Starting the assembly of information to later execute a copy script or manual cp statements ...' # find $path -size ${thismany}c -name "$filespec" -exec cp $index {} \; IFS= result=`find $path -size ${thismany}c -name "$filespec" -exec grep -H "$findstring" {} \;` if [ -z "$result" ]; then echo "No candidate files for change" exit else indexsed=`echo "$index" | sed '/\//s//~!/g'` echo $result | cut -d : -f 1 | uniq | sed "/^/s//cp $indexsed /g" | sed '/\~\!/s//\//g' echo '' echo 'Optional ksh file as above to create and get edit and execute advice eg. ./therealchange.ksh' read thisksh if [ ! -z "$findstring" ]; then echo "#/bin/ksh" > $thisksh echo $result | cut -d : -f 1 | uniq | sed "/^/s//cp $indexsed /g" | sed '/\~\!/s//\//g' >> $thisksh echo "vi $thisksh # can edit, with a wq! to save, in vi editor" echo "ksh $thisksh # can execute the statements to perform the copying" exit fi fi echo '' echo 'Finished' fi else echo "$path path is non-existant" fi fi fi else echo "$index file not found" fi exit