Find and Replace in multiple files (Shell script)

Shell Programming and Scripting

Kindly Note - This is a Single User Post by Forum Member oombera Regarding:
Find and Replace in multiple files (Shell script).
Please Follow The Primary Link Above to View the Full Discussion.

Old 08-21-2002
oombera's Unix or Linux Image
oombera oombera is offline Forum Advisor  
Registered User
Join Date: Aug 2002
Last Activity: 3 October 2004, 6:07 PM EDT
Location: Cleveland, OH
Posts: 804
Thanks: 0
Thanked 6 Times in 5 Posts
If I understand what you're asking, this code should do what you want (ksh):

cd your_pathname
for i in `lx`; do
FOUND=`grep ABCD $i`
if [ "$FOUND" ]
sed -e 's/ABCD/DCBA/g' < $i > $TMP
mv $TMP $i
echo "The file $i does not include the word ABCD"

This script reads each file in your_pathname, searches for the string ABCD, and either replaces it with DCBA or alerts you that the string ABCD was not found.

Last edited by oombera; 08-21-2002 at 10:49 AM..