Im working on a shell script that uses three parameters, a string to replace, the string replacing, and a file name.
In this script it makes a back up file before the replacement occurs. However I want to be able to either search the file to see if it has the string and if it doesnt dont create a backup. Or do the substition and compare the two files. I am lost, I assume it would be easier to search the file for the string then go from there, but this is what I have.
#!/bin/csh
set old_pattern="$1"
set new_pattern="$2"
set file_name="$3"
mv $file_name $file_name.bak
sed -e "s/$old_pattern/$new_pattern/g" $file_name.bak > $file_name
myScript this will be five arguments
...
$1=this
$2=will
$3=be
($4 and $5 are never used
Instead:
myScript "this will" "be three" arguments
...
$1="this will"
$2="be three"
$3=arguments