Shell script to replace strings in all files under directory recursively
Published on Sat 30 Jun 2007 06:06 ( 3 years, 2 months ago)
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:
- SSH could be a nightmare for corporate firewall...
- Unix alike Symbolic Links on Windows XP (maybe vista)
- Recursive touch
- Shell script to replace strings in all files under directory recursively
Search related in web:
Custom Search