Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search/replace a pattern in multiple files

Status
Not open for further replies.

sepgs2004

Programmer
Apr 25, 2007
5
US
Hi
Good morning. I would like to search this: onkeyup="autoFormatDate(this,event)" and replace with onkeydown="return applyDateFormatting(this,event)" in all our JSP files. It is crazy if we do manually; they are 400 pages. All JSP pages are under one folder, let us say c:\jboss\server\deploy\abc.ear\abc.war\jsp\*

Appreciate your time and help
 
What have you tried so far and where in your code are you stuck ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks for your question. I am on my way trying out. Let you know once I get stuck.
 
I got several scripts on line... however one of my colleague have RegExBuddy where we have to just write correct Reg Expression (for match and replace), it will apply on multiple files.

Example bash script, that we could use.
#!/bin/bash
FILES=`find . -name *.txt`
for file in $FILES
do
if [ -f "$file" ]
then
cp $file $file.old
sed 's/paul/SOUL/g' $file.old > $file
continue
fi
done
exit 0


Thanks again.
 
To change a file in place, you may use

Code:
sed -i 's/before/later/g' file
I see you mixing unix programs (bash) and Windows syntax (C:\...).
Maybe the unix-utils are interesting for your needs:

There is a find.exe in /WIN_HOME$/system32/... which might get in your way, so use the complete path for find.

don't visit my homepage:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top