I am looking for a shell script which serves the below purpose.
Please find below the algorithm for the same and any help on this would be highly appreciated.
1)set of strings need to be replaced among set of files(directory may contain different types of files)
2)It should search for the type of files for which replace must be done
Please find below the algorithm for the same and any help on this would be highly appreciated.
######
#below mapped texts must be replaced
######
SEARCH_N_REPLACE={
abc = test1
efg = test2
gfdg = test3
}
######
#directory may contain pdf/txt/jpg files but it should only consider the #mentioned files here {html,htm,css,js}.
#######
SEARCH_IN_FILES= {html,htm,css,js}
######
foreach line in sync.log #line means each file path
foreach ext SEARCH_IN_FILES #should search for extension type of file
if line.ext is ext #if matches the extension
foreach term SEARCH_N_REPLACE
searchterm=parse:SEARCH_N_REPLACE
replaceterm=parse:SEARCH_N_REPLACE
perl -pie 's/searchterm/replaceterm'
perl -pie 's/searchterm/replaceterm' line
Thanks for the script. As the data for the type of files and the replacements will be dynamic, could you please let me know how can i parse the search term and replace among the files as mentioned in the algorithm using for loops.
Thanks a lot for the help .
---------- Post updated at 07:33 AM ---------- Previous update was at 07:05 AM ----------
---------- Post updated at 07:34 AM ---------- Previous update was at 07:33 AM ----------
Im using bash shell. scripting with .sh
---------- Post updated at 07:36 AM ---------- Previous update was at 07:34 AM ----------
Im using bash shell. scripting with .sh
---------- Post updated at 07:50 AM ---------- Previous update was at 07:36 AM ----------
$ cat test
#!/bin/bash
SEARCH_IN_FILES="html htm css js"
declare -A MYMAP=( [abc]=test1 [efg]=test2 [gfdg]=test3 )
while read line;do
if grep -w "${line##*.}" <<<$SEARCH_IN_FILES >/dev/null; then
for i in "${!MYMAP[@]}";do
sed -i 's/'"$i"'/'"${MYMAP[$i]}"'/g' $line
done
fi
done <"log"
$ bash --version
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
$ uname -a
Linux xxx.xxx.xxx 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
---------- Post updated at 01:34 AM ---------- Previous update was at 01:28 AM ----------
Hi Akshay,
Could you please help me with the shell script for deployment if possible?
It is posted as below in the forum:
"Help needed with a shell script for deploying ear file to a weblogic server using WLST "