SED command using multiple input files

What is the syntax to use multiple input files in a SED command. i.e. substitute a word with a phrase in every file in a directory.

for every file in /usr/include that has the word "date" in the file
grep -l '\<date\>' /usr/include/*.h
find each occurrence of the word "time" in the file & replace it with "Smarts" and write the results to newfile.txt
sed -n 's/\<time\>/Smarts/pg' [results of the grep -l query above] >>newfile.txt
I tried starting with the grep & pipe to sed. it just reads the filenames in, not the file.

I can sed -n 's/\<time\>/Smarts/pg' /usr/include/*.h >>newfile.txt but that uses every file in /usr/include, not just the ones containing the word "date"

Looks like I need your help!

You can try..

grep -l '\<date\>' /usr/include/*.h | xargs -iVAR sed -n 's/\<time\>/Smarts/pg' VAR > newfile.txt

Assuming that the text you are matching against in the files is "<date>" and "<time>" (< and > are not special in sed/grep basic regular expressions and do not require escaping), the following approach is safe regardless of what characters the filenames may contain:

find /usr/include -type f -name \*.h -exec sh -c '
    for f; do
        grep -q "<date>" "$f" && sed -n "s/<time>/Smarts/gp" "$f" >> newfile.txt
    done
' sh {} +

Regards,
Alister

grep -l '\<date\>' /usr/include/*.h |while read LINE
do
    sed 's/<time>/Smarts/g' $LINE >> newfile.txt
done