I want to test if a pattern exists in a file.
- If the pattern exists (In a file among a list), do a replacement and update the corresponded file.
- If the pattern doesn't exists, do nothing.
So far I have done:
if [ -f $((`awk '/Pattern1/' $FILE`))];then
sed 's/Pattern1/\nWORD/g' $FILE > a
mv a $FILE
fi
But, when I test it, I get the following error:
syntax error: invalid arithmetic operator
And I don't want to evaluate the numeric part, just if the pttern~string is there or not.
Input of file 1
Rho = 1.1955904623E+02 Rho at Nucleus = 1.1955904594E+02
Input of file2
Rho = 1.1955904623E+02