SunQuest
           BSD Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsBSD Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old October 26th, 2002, 07:16 PM
Ted Striker Ted Striker is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Posts: 409 Ted Striker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Search and replace utility

Hi everybody.

Does anyone use a command line search and replace tool?

For example, say I want to go through every text file in a directory and replace "devshed" with "devshedforums"

I found one at one time but by accident. Now I can't find it and have been searching forever to find something!

This would save me ALOT of time...

Reply With Quote
  #2  
Old October 26th, 2002, 07:39 PM
Ted Striker Ted Striker is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Posts: 409 Ted Striker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Here's the utilities I am going to audition for the part!

glark
glimpse
isearch
replaceit
sarep

Reply With Quote
  #3  
Old November 3rd, 2002, 03:05 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 39 m 55 sec
Reputation Power: 184
i use sed and the bash for this task:
Code:
for i in *; do
  cat "$i" | sed -e "s/devshed/devshedforums/" >/tmp/tmpfile
  cat /tmp/tmpfile > "$i"
done
__________________
--
Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more.

Reply With Quote
  #4  
Old November 3rd, 2002, 04:57 PM
Ted Striker Ted Striker is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Posts: 409 Ted Striker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Thumbs up

Danke!

Reply With Quote
  #5  
Old November 4th, 2002, 03:41 PM
ultraslacker's Avatar
ultraslacker ultraslacker is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2002
Posts: 56 ultraslacker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
I use perl - here's the command



perl -p -i.bak -e 's#old_string#new_string#g' /path/files

-p means loop
-i.bak will copy originals to .bak, use just -i for no backup if you are sure
-e designates expression.

awk or sed would do the trick as well.
__________________
Casuistry Agnostic

Reply With Quote
  #6  
Old November 4th, 2002, 04:02 PM
Ted Striker Ted Striker is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Posts: 409 Ted Striker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Thumbs up

Thanks ultraslacker.

These commands are big timesavers!

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsBSD Help > Search and replace utility


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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 On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway