I’ve been writing a script to go through a folder and the sub folders to grep text and edit the file if the text is found.
The folder is one of several in the root of a hard drive. I cd into one of the folders to prevent the find command from doing my laptop’s root drive; that or leave a dummy file in the root.
The find command always does the entire hard drive and finishes in the starting folder.
Is there a way to get find to limit activity to the starting folder and all sub folders?
cd "Q:Zeus"
find . -iname "*xml" -maxdepth 6| while read f
do
echo $f
grep -q "<Name>ARTIST" "$f"
artit=$(("$?"))
grep -q "SUMMARY" "$f"
sumit=$(("$?"))
if [[ $artit -eq 0 ]]
then
artist=`sed -n '/'<Name>ARTIST'/=' "$f"`
artmin=$(($artist-1))
artmax=$(($artist+2))
echo "$artmin"
echo "$artmax"
sed -i "$artmin,$artmax d" "$f"
fi
if [[ $sumit -eq 0 ]]
then
summary=`sed -n '/'SUMMARY'/=' "$f"`
summin=$(($summary-1))
summax=$(($summary+2))
echo "$summin"
echo "$summax"
sed -i "$summin,$summax d" "$f"
fi
done