HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Search and replace a string inside a shell scr...
Operating System - HP-UX
1834408
Members
1877
Online
110067
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2007 06:52 PM
08-30-2007 06:52 PM
Search and replace a string inside a shell script
Hi,
I want to write a shell script which would search and replace a sting for the list of files. I tried using sed inside the shell script, but it doesn't seem to work. could you pls help me with this.
I want to write a shell script which would search and replace a sting for the list of files. I tried using sed inside the shell script, but it doesn't seem to work. could you pls help me with this.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2007 06:59 PM
08-30-2007 06:59 PM
Re: Search and replace a string inside a shell script
#!/bin/bash # This script will search and replace all regular files for a string # supplied by the user and replace it with another string. # # Written by Daniel McCarthy # daniel.mccarthy@linuxphile.org # function usage { echo "" echo "Search/replace script" echo " Written by Daniel McCarthy" echo " daniel.mccarthy@linuxphile.org" echo " http://linuxphile.org" echo "" echo "Not enough parameters provided." echo "Usage: ./$0 searchstring replacestring" echo "Remember to escape any special characters in the searchstring or the replacestring" echo "" } #check for required parameters if [ ${#1} -gt 0 ] && [ ${#2} -gt 0 ]; then for f in `find -type f`; do if grep -q $1 $f; then cp $f $f.bak echo "The string $1 will be replaced with $2 in $f" sed s/$1/$2/g < $f.bak > $f rm $f.bak fi done else #print usage informamtion usagefi
It's kind of fun to do the impossible
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2007 12:56 AM
09-03-2007 12:56 AM
Re: Search and replace a string inside a shell script
Hi,
see the atthaced script.
HTH,
Art
see the atthaced script.
HTH,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2007 03:14 PM
09-03-2007 03:14 PM
Re: Search and replace a string inside a shell script
Hi Guys,
Thanks a lot, it was really helpfull.
Thanks a lot, it was really helpfull.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP