The stream editor sed inserts text before a specified pattern.

sed -i '/pattern/i\inserted text' *.txt

The -i flag enables editing in place.