I'm trying to write a bash script to put text at the beginning of all files in all subdirectories only if:
- The file does not contain that text
- The file contains the company's name, the word River, or the word Systems
Here's what I have so far:
for i in $(find -name *.cpp -type f -print)
do
if ! grep -r 'This document contains technical data' $i && grep -r 'company name' $1 || grep-r 'River' $i || grep -r 'Systems' $i; then
#add text
Right now, the file that does not contain any keywords is not getting altered (as expected), but for files that have the text already and the keywords, they get altered. I tried using [] around the || statements, but the result was the same. Any suggestions?
grep-r 'River' $i
(missing a space betweengrep
and-r
) – scottbb Apr 01 '22 at 05:12