My script to replace strings in ASCII files

Jerry McAllister jerrymc at clunix.cl.msu.edu
Wed Jan 11 12:47:31 PST 2006


> 
> 
> Hello!
> 
> Just curious, what do I need to do to be able to execute this script like:
> 
> $ text-replace old_string new_string

Check out tr(1).
It does a good job of it with very simple rules.

////jerry

> 
> I find it a bit inconvenient having to edit the script for every thing I need to replace.
> 
> Thanks,
> Kristian
> 
> #!/usr/local/bin/bash
> #
> #   Replace old with new inside all text files.
> #   $URBAN: text-replace.sh,v 1.0 2005/10/24 15:09:05 vaaf Exp $
> #
> 
> for file in `find . -type f ! -name ".*"`; do
> 
> 	if [ "`file -b "$file" | grep text`" != "" ]; then
> 
> 		sed -i '' "s/old/new/g" "$file"
> 
> 		echo "$file: Done"
> 
> 	fi
> 
> done
> 
> 
> 
> _______________________________________________
> freebsd-questions at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe at freebsd.org"
> 



More information about the freebsd-questions mailing list