Browse files

tool script for replace string in a file.

  • Loading branch information...
1 parent 4c63582 commit b18fda986db4532180126f9666a51b45939ee7ac @soarpenguin committed Dec 26, 2013
Showing with 24 additions and 0 deletions.
  1. +24 −0 bashrc/replace.sh
View
24 bashrc/replace.sh
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+#Example Usage: ./replace.sh *.txt aaaa bbbb"
+usage()
+{
+ echo "./replace.sh \"file_type\" src_string dst_string"
+ echo "Exapmle: ./replace.sh \"*\" aaaa bbbb"
+ exit
+}
+
+if [ ! -e "$1" ]; then
+ echo "please check the file $1.";
+ usage
+fi
+
+if [ -z $2 -o -z $3 ]; then
+ usage
+fi
+
+
+for f in $1; do
+ sed s/$2/$3/g $f > $f.bak
+ mv -f $f.bak $f
+done

0 comments on commit b18fda9

Please sign in to comment.