473,508 Members | 2,303 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Replace all occurrences of a string

Is there a utility or command that will allow me to replace all occurrences
of a string within all files in a directory?

I'm trying to mass update IP addresses of all DNS zone files in my
/var/named/ folder.
Jul 19 '05 #1
2 8764
In article <aO********************@adelphia.com>, Shabam
<xx***********@hotmail.com> wrote:
Is there a utility or command that will allow me to replace all occurrences
of a string within all files in a directory?

I'm trying to mass update IP addresses of all DNS zone files in my
/var/named/ folder.


You can use a Perl one-liner of the type

perl -pi'bak' -e 's/bar/baz' /var/named/*

See 'perldoc perlrun' for more options. Try it out on some test files
first!
Jul 19 '05 #2
Jim Gibson wrote:
In article <aO********************@adelphia.com>, Shabam
<xx***********@hotmail.com> wrote:

Is there a utility or command that will allow me to replace all occurrences
of a string within all files in a directory?

I'm trying to mass update IP addresses of all DNS zone files in my
/var/named/ folder.

You can use a Perl one-liner of the type

perl -pi'bak' -e 's/bar/baz' /var/named/*

See 'perldoc perlrun' for more options. Try it out on some test files
first!


You'll need the closing slash and probably the g modifier on that s///.

perl -pi.bak -e 's/oldtext/newtext/g' /var/named/*

More sophisticated stuff with /e.

perl -pi -e 's/(10\.0\.)(\d+)(\.\d+)/$1.($2+100).$3/e' /var/named/*

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
30393
by: o_swas | last post by:
Hello, I have a JavaScript string. I want to replace all consecutive occurrences of whitespace characters like spaces, tabs, newlines, and form feeds with another string. For example, say I...
1
9027
by: Michael Yanowitz | last post by:
Hello: I am hoping someone knows if there is an easier way to do this or someone already implemented something that does this, rather than reinventing the wheel: I have been using the...
3
16902
by: TOXiC | last post by:
Hi everyone, First I say that I serched and tryed everything but I cannot figure out how I can do it. I want to open a a file (not necessary a txt) and find and replace a string. I can do it...
1
2788
by: coolami4u | last post by:
I need a program that simulates the search-and-replace operation in a text editor. The program is to have only three function calls in main. The first function prompts the user to type a string of...
8
80204
by: Johny | last post by:
Let's suppose s='12345 4343 454' How can I replace the last '4' character? I tried string.replace(s,s,'r') where 'r' should replace the last '4'. But it doesn't work. Can anyone explain why?...
3
11135
by: Christoph Krammer | last post by:
Hello everybody, I wanted to use re.sub to strip all HTML tags out of a given string. I learned that there are better ways to do this without the re module, but I would like to know why my code...
5
25506
by: herman | last post by:
How can I replace all occurrences of a character with another character in std string? For example, I want to replace '/' with '+' in my std::string I have looked at the replace() method in...
10
18612
by: Lonifasiko | last post by:
Hi, Just want to replace character at index 1 of a string with another character. Just want to replace character at that position. I thought Replace method would be overloaded with an index...
5
1530
by: MLH | last post by:
I have memo field containing imported data. In it are numerous Chr(13) & Chr(13) & Chr$(10) occurrences. How do I rid my table of all occurrences of this 3-character string ? Generally there is...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7123
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7324
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7382
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7495
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5052
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.