Here is a shell script to find all txt files and add string “my_begin” to the beginning of files.
You can change the string for your target.
set -e
folder="./"
files=()
echo "start to find txt under folder: "$folder
find $folder -name "*.txt" -print0 >tmpfile
while IFS= read -r -d $'\0'; do
files+=("$REPLY")
done < tmpfile
len=${#files[*]}
echo ${files[@]} #print all
echo "----- length is "${len}
#exit 0
for (( i=0; i<${len}; i++ ))
do
echo "input file: " ${files[$i]}
filename=${files[$i]}
x=`echo -n "my_begin"; cat "${filename}"`
echo "$x" > "$filename"
done