123HELPDESK

IT professionals voor ondernemers

replace script PDF Afdrukken
This script will look for files with a name that contains
a specific string and inside files with that name, it will  
replace all occurences of another specific string with a
third specified string


#!/bin/bash 
 echo "#############################################################" 
 echo "This script will look for files with a name that contains " 
 echo "a specific string and inside files with that name, it will " 
 echo "replace all occurences of another specific string with a " 
 echo "third specified string". 
 echo "" 
 echo "" 
 echo "Please write the string that identifies the name (or part of " 
 echo "the name) of the files you wish to replace text in, example: pom.xml "  
 echo "" 
 read -e FILE_STRING 
 
echo "" 
echo "Please write the string that you wish to replace, " 
echo "example 3.3.2-SNAPSHOT:" 
echo "" 
read -e SEARCH_STRING 
 
echo "" 
echo "Please write the string that you wish to replace [$SEARCH_STRING]" 
echo "with, example 3.4-SNAPSHOT:" 
echo "" 
read -e REPLACE_STRING 
 
echo "Searching....." 
echo "" 
 
for i in `find . -name "*$FILE_STRING*"` 
do 
 echo -n "---------- Parsing file [$i] .... " 
 SED_STRING="s/$SEARCH_STRING/$REPLACE_STRING/g" 
 perl -i -pe $SED_STRING $i 
 echo " Done! ----------" 
done; 
 
echo "#############################################################"

 
< Vorige   Volgende >