Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
search and replace
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
sunil  
View profile  
 More options Nov 4 2003, 10:20 pm
Newsgroups: linux.help
From: sunil <fingersmalloyNO_S...@yahoo.co.nz>
Date: Wed, 05 Nov 2003 16:19:16 +1300
Local: Tues, Nov 4 2003 10:19 pm
Subject: search and replace

I've found a number of scripts on the web
using sed or perl, that can search a number of
files in a directory, and replace it with a
provided string.

I would like do such a search and replace operation
that goes into subdirectories,
and replaces a block of text that spans many lines,
and replace it with a string.

I looked at rpl, but couldn't figure out how
to use it to replace a text block.

Can anyone help?
Thanks


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Carsten Schmitz  
View profile  
 More options Nov 5 2003, 3:46 am
Newsgroups: linux.help
From: goo...@humanprototype.com (Carsten Schmitz)
Date: 5 Nov 2003 00:46:05 -0800
Local: Wed, Nov 5 2003 3:46 am
Subject: Re: search and replace

> I would like do such a search and replace operation
> that goes into subdirectories,
> and replaces a block of text that spans many lines,
> and replace it with a string.

I use a perl one-liner combined with find, like this:

perl -pi -e s#text1#text2# `find . -name "*.php"`

This goes into each *.php file in every subdirectory under the current
dir, and replaces text1 with text2. You can replace *.php with *.html
or * obviously. If you need slashes in the substitution (e.g. to alter
a pathname in multiple html files), you need to mask with a backslash,
such as s#var#var\/log#

Oh, and I think (no guarantee though, try it) it also creates some
kind of .bak files so you have backups, just in case.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
sunil  
View profile  
 More options Nov 5 2003, 8:08 am
Newsgroups: linux.help
From: sunil <fingersmalloyNO_S...@yahoo.co.nz>
Date: Thu, 06 Nov 2003 02:08:50 +1300
Local: Wed, Nov 5 2003 8:08 am
Subject: Re: search and replace

Carsten Schmitz wrote:

s:

> perl -pi -e s#text1#text2# `find . -name "*.php"`

> This goes into each *.php file in every subdirectory under the current
> dir, and replaces text1 with text2. You can replace *.php with *.html
> or * obviously. If you need slashes in the substitution (e.g. to alter
> a pathname in multiple html files), you need to mask with a backslash,
> such as s#var#var\/log#

> Oh, and I think (no guarantee though, try it) it also creates some
> kind of .bak files so you have backups, just in case.

How do I use the provided script to replace a string
that spans many lines?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Noi  
View profile  
 More options Nov 5 2003, 10:35 am
Newsgroups: linux.help
From: Noi <n...@siam.com>
Date: Wed, 05 Nov 2003 15:34:34 GMT
Local: Wed, Nov 5 2003 10:34 am
Subject: Re: search and replace

You might look at sed examples.  Something like:  

 sed  s/replace this/with this/ filename
 sed "s/_samba/_samba\/\samba/" filename


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »