Shell script to replace strings in all files under directory recursively


Shell script to replace strings in all files under directory recursively

Published on Sat 30 Jun 2007 06:06 ( 2 years, 8 months ago)
Shell script Linux/Unix

In one of my project I need to replace some kind of strings in hundreds if file,  the code paste here is for specific usage, but it could be easily changed to do something else.

It will scan all *.xml files in current directory and in sub directories, replace the value of two attributes to a big value.

































































#!/bin/bash 
# Get List of Files to Be Replaced
file_list=`find . -name "*.xml" -type f` 
# Define Target String to Be Replaced & Destination String for Substitution
echo " Replacing *.xml file's timeout to a big value " 
# Perform Substitution
for fn in $file_list
do 
if ( test $fn != ./`basename $0` ) 
then
ffnt="$fn.temp" 
echo "Processing $fn ...... "  
sed 's/responseReadTimeout="[0-9][0-9]*"/responseReadTimeout="999999"/g'  $fn > $ffnt 
sed 's/socketReadTimeout="[0-9][0-9]*"/socketReadTimeout="999999"/g' $ffnt > $fn 
rm $ffnt
echo "  Done " 
fi
done


Related posts:


Search related in web:

Custom Search

RSS Feed

One click subscribe this blog in your google reader!

Be social!


Want to say something here? please sign in



Blog posts link to this page
What are friends tweeting?
Tags cloud
Monthly Archives