Sponsored Content
Top Forums Shell Programming and Scripting Creating a sed script to change ip addresses in a file Post 302600942 by Scott on Wednesday 22nd of February 2012 12:42:49 PM
Old 02-22-2012
It will likely print ? if nothing is substituted (i.e. if the string to replace doesn't exist, or you run it for a second time).
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

creating virtual ip addresses

i am running solaris 9 i now how to create virtual ip address but how do i keep them so when the server reboots they are still there?...THANX (2 Replies)
Discussion started by: rmuhammad
2 Replies

2. UNIX for Dummies Questions & Answers

How do I change IP addresses in command mode...

How do I change IP addresses in command mode? i need to assign custom (non DHCP) addresses from the command line. Actually I also need to know how to change the subnet mask, the gateway and the primary, secondary, ... dns servers. (6 Replies)
Discussion started by: Super.Anyak
6 Replies

3. Shell Programming and Scripting

How to change this file with SED?

I have a file like below: I want to delete the rows which begining with "BC" "CD" and "TY" . then change every fields into one row like this at last delete the head words : USing awk to change it is not hard. I want to know how to do this work using SED ? Thank you! ... (4 Replies)
Discussion started by: bejgirl
4 Replies

4. IP Networking

Ip Addresses With Hardware Change

I have 2 identical printers with the same IP on my network. One is only used as a backup for the primary printer and both are never on line at the same time. The goal was to always keep only 1 on and have an use the other printer as an immediate backup if necessary. But when I switch the cable I... (4 Replies)
Discussion started by: golfs4us
4 Replies

5. Shell Programming and Scripting

script to get all ip addresses of servers into a file

Hi all i need to create a script that pings every server in my range (0-254) adn then returns the values to a file? can anyone please help. i am working in the tcsh ( and yes i know how to ping ) but i dont know how to ping them all in one script without copying and pasting a 254 times? ... (1 Reply)
Discussion started by: brian112
1 Replies

6. UNIX for Dummies Questions & Answers

sed script to change timecode string

Need some help. I need to run a script to modify a csv file. Here is an example off a few lines from the csv 98M-01.WAV,98M,01,00:00:49,01:07:36:00,"MIX",,"BOOM-MKH50",,,,,,,,,,"", 98L-01.WAV,98L,01,00:00:51,01:01:45:00,"MIX",,"BOOM-MKH50",,,,,,,,,,"", I need a sed script to find all... (4 Replies)
Discussion started by: Vrc2250
4 Replies

7. UNIX for Advanced & Expert Users

Change user while creating spool file

Hi, I have a script which generate a HTML file from a unix user. Script spool the data extracted from DB using sqlplus. Problem is html file which gets generated is automatically assigned/owned with oracle user so my unix user just having read only permission to that HTML file. So I want... (1 Reply)
Discussion started by: sv0081493
1 Replies

8. UNIX for Beginners Questions & Answers

File name change with sed

I have a bunch of text files like this: Sample_S1_L001_R1.txt Sample_S10_L001_R1.txt Sample_S11_L001_R1.txt I am using the following script to add a 0 to those files with a single digit after the S: ls *.txt | sed 's/\(.*_S\)\(_.*\)/mv & \10\2/' | sh And then the following script to... (4 Replies)
Discussion started by: Xterra
4 Replies

9. UNIX for Beginners Questions & Answers

Using sed to change file into an awk script

Hi I want to use sed to change a text files input into an awk script. For example if the input says " chord -- english " I want to change this using sed 's/pattern 1 /pattern 2 /'g filename but I don't understand how to use part of the pattern 1 to input that into pattern 2 . Like after... (10 Replies)
Discussion started by: enforcer
10 Replies

10. UNIX for Beginners Questions & Answers

awk or sed script to count number of occurrences and creating an average

Hi Friends , I am having one problem as stated file . Having an input CSV file as shown in the code U_TOP_LOGIC/U_HPB2/U_HBRIDGE2/i_core/i_paddr_reg_2_/Q,1,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,0,0... (4 Replies)
Discussion started by: kshitij
4 Replies
Sub::Override(3pm)					User Contributed Perl Documentation					Sub::Override(3pm)

NAME
Sub::Override - Perl extension for easily overriding subroutines SYNOPSIS
use Sub::Override; sub foo { 'original sub' }; print foo(); # prints 'original sub' my $override = Sub::Override->new( foo => sub { 'overridden sub' } ); print foo(); # prints 'overridden sub' $override->restore; print foo(); # prints 'original sub' DESCRIPTION
The Problem Sometimes subroutines need to be overridden. In fact, your author does this constantly for tests. Particularly when testing, using a Mock Object can be overkill when all you want to do is override one tiny, little function. Overriding a subroutine is often done with syntax similar to the following. { local *Some::sub = sub {'some behavior'}; # do something } # original subroutine behavior restored This has a few problems. { local *Get::some_feild = { 'some behavior' }; # do something } In the above example, not only have we probably misspelled the subroutine name, but even if their had been a subroutine with that name, we haven't overridden it. These two bugs can be subtle to detect. Further, if we're attempting to localize the effect by placing this code in a block, the entire construct is cumbersome. Hook::LexWrap also allows us to override sub behavior, but I can never remember the exact syntax. An easier way to replace subroutines Instead, "Sub::Override" allows the programmer to simply name the sub to replace and to supply a sub to replace it with. my $override = Sub::Override->new('Some::sub', sub {'new data'}); # which is equivalent to: my $override = Sub::Override->new; $override->replace('Some::sub', sub { 'new data' }); You can replace multiple subroutines, if needed: $override->replace('Some::sub1', sub { 'new data1' }); $override->replace('Some::sub2', sub { 'new data2' }); $override->replace('Some::sub3', sub { 'new data3' }); If replacing the subroutine succeeds, the object is returned. This allows the programmer to chain the calls, if this style of programming is preferred: $override->replace('Some::sub1', sub { 'new data1' }) ->replace('Some::sub2', sub { 'new data2' }) ->replace('Some::sub3', sub { 'new data3' }); A subroutine may be replaced as many times as desired. This is most useful when testing how code behaves with multiple conditions. $override->replace('Some::thing', sub { 0 }); is($object->foo, 'wibble', 'wibble is returned if Some::thing is false'); $override->replace('Some::thing', sub { 1 }); is($object->foo, 'puppies', 'puppies are returned if Some::thing is true'); Restoring subroutines If the object falls out of scope, the original subs are restored. However, if you need to restore a subroutine early, just use the restore method: my $override = Sub::Override->new('Some::sub', sub {'new data'}); # do stuff $override->restore; Which is somewhat equivalent to: { my $override = Sub::Override->new('Some::sub', sub {'new data'}); # do stuff } If you have override more than one subroutine with an override object, you will have to explicitly name the subroutine you wish to restore: $override->restore('This::sub'); Note "restore()" will always restore the original behavior of the subroutine no matter how many times you have overridden it. Which package is the subroutine in? Ordinarily, you want to fully qualify the subroutine by including the package name. However, failure to fully qualify the subroutine name will assume the current package. package Foo; use Sub::Override; sub foo { 23 }; my $override = Sub::Override->new( foo => sub { 42 } ); # assumes Foo::foo print foo(); # prints 42 $override->restore; print foo(); # prints 23 METHODS
new my $sub = Sub::Override->new; my $sub = Sub::Override->new($sub_name, $sub_ref); Creates a new "Sub::Override" instance. Optionally, you may override a subroutine while creating a new object. replace $sub->replace($sub_name, $sub_body); Temporarily replaces a subroutine with another subroutine. Returns the instance, so chaining the method is allowed: $sub->replace($sub_name, $sub_body) ->replace($another_sub, $another_body); This method will "croak" is the subroutine to be replaced does not exist. override my $sub = Sub::Override->new; $sub->override($sub_name, $sub_body); "override" is an alternate name for "replace". They are the same method. restore $sub->restore($sub_name); Restores the previous behavior of the subroutine. This will happen automatically if the "Sub::Override" object falls out of scope. EXPORT
None by default. BUGS
Probably. Tell me about 'em. SEE ALSO
o Hook::LexWrap -- can also override subs, but with different capabilities o Test::MockObject -- use this if you need to alter an entire class AUTHOR
Curtis "Ovid" Poe, "<ovid [at] cpan [dot] org>" Reverse the name to email me. COPYRIGHT AND LICENSE
Copyright (C) 2004-2005 by Curtis "Ovid" Poe This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.2 or, at your option, any later version of Perl 5 you may have available. perl v5.10.1 2010-04-01 Sub::Override(3pm)
All times are GMT -4. The time now is 08:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy