Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > find and replace a string

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-12-07, 20:21
saccskiz saccskiz is offline
Registered User
 
Join Date: Feb 2004
Posts: 136
find and replace a string

I currently have a shell script (findreplace.ksh) that finds a word and replaces it with another word for all files in the specified directory
#findreplace.ksh :
perl -e "s/${1}/${2}/g;" -pi $(find ${3}/ksh -type f)

Hence I would run the script as :
findreplace dummy nodummy temp

This would replace all occurances of dummy to nodummy in the temp/ksh folder.

Now how do I do the following :
If my arguments ${1} and ${2} have spaces in them, what option can I give to make it work ?
For example, I need to replace the word <I am a Dummy> with <Not anymore a dummy" in the same fashion ?
Also, I am interested in knowing if there are any other options to doing a find and replace(besides the perl command)
Thanks
Reply With Quote
  #2 (permalink)  
Old 09-12-07, 20:36
vgersh99 vgersh99 is offline
Registered User
 
Join Date: Apr 2004
Location: Boston, MA
Posts: 324
Code:
findreplace 'I am a Dummy' 'Not anymore a dummy' temp
__________________
vlad
+-----------------------+
| #include <disclaimer.h> |
+-----------------------+
Reply With Quote
  #3 (permalink)  
Old 09-15-07, 06:12
Tyveleyn Tyveleyn is offline
Registered User
 
Join Date: Aug 2006
Location: The Netherlands
Posts: 200
Type on the command line:
Code:
$ for i in "`ls *"I am a dummy"*`" > do > mv "$i" "`echo "$i" | sed 's/I am a dummy/Not anymore a dummy/'`" > done
This is done in Linux so maybe the quoting thing works a little different in other UNIX systems. Spaces in filenames is not what UNIX is made for anyway...

Regards

Last edited by Tyveleyn : 09-15-07 at 06:51.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On