Linker IT Software
Google
Web www.oraxcel.com
menubar-top-links menubar-top-rechts
Home Help Search Login
Welcome, Guest. Please Login.
SQL*XL: Database to Excel bridge litLIB: Excel power functions pack ExcelLock: Locking and securing your valuable Excel spreadsheets encOffice: Protect your Excel file easy and safe encOffice: Protect your Excel file easy and safe
Pages: 1
sed: Search and replace in multiple files (Read 5546 times)
Gerrit-Jan Linker
YaBB Administrator
*****




Posts: 75
sed: Search and replace in multiple files
17.08.08 at 12:42:27
 
sed: Search and replace in multiple files using sed
 
To replace text in multiple files the sed utility can be used. To replace the text "Excel 2003" with "Excel 2007" in all html files the following command can be used:
sed -i "s/Excel 2003/Excel 2007/g" *.html
 
The -i option indicates in place editing. In quotes the search replace command is given. This is the same command as you would use in vi to globally search and replace. The s denotes the search, the g denotes a global search. The search and replace strings are separated with a slash symbol.
 
A search and replace can also be done using a GUI frontend. See SearchReplace project:
http://www.oraxcel.com/projects/searchreplace/
 
See also:
SearchReplace: Text search and replace tool.
http://www.oraxcel.com/projects/searchreplace/
LIT Software Forums - vi editor
http://www.oraxcel.com/cgi-bin/yabb2/YaBB.pl?num=1202389717
LIT Software Forums - Use UNIX commands on windows
http://www.oraxcel.com/cgi-bin/yabb2/YaBB.pl?num=1217847568/0
Back to top
 
« Last Edit: 18.03.10 at 08:41:11 by Gerrit-Jan Linker »  

Gerrit-Jan Linker
Linker IT Software
Email WWW Gerrit-Jan Linker   IP Logged
Gerrit-Jan Linker
YaBB Administrator
*****




Posts: 75
Re: Search and replace in multiple files using sed
Reply #1 - 15.11.08 at 21:17:34
 
In combination with the recursive file search you get the following command. It searches from the current directory for all files matching *.input. It feeds all the files to the sed program where the string RAS4 will be replaced by RAS2.
 
find . -name *.input -exec sed -i "s/RAS4/RAS2/g" {} \;
Back to top
 
 

Gerrit-Jan Linker
Linker IT Software
Email WWW Gerrit-Jan Linker   IP Logged
Pages: 1