Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Replace a string after a word

by kcott (Abbot)
on Jan 06, 2014 at 15:04 UTC ( #1069534=note: print w/ replies, xml ) Need Help??


in reply to Replace a string after a word

G'day nithins,

A little more information regarding the file and the string to be replaced would have been useful. For instance, how big is the file? how many replacements are possible in the file? if more than one, how many replacements are possible per record? Also, are there any constraints such as time, memory or disk space?

Bearing in mind the unknowns, the following (pm_1069470.pl) may be suitable for your needs:

#!/usr/bin/env perl use strict; use warnings; use autodie; use Tie::File; tie my @records, 'Tie::File', 'pm_1069470.txt'; s/user={hhhfj}jshdfjhdfjh\\=/user=newvalue/ for @records; untie @records;

Sample run:

$ cat pm_1069470.txt blah blah blah user={hhhfj}jshdfjhdfjh\= whatever user=something else user={hhhfj}jshdfjhdfjh\= other data $ pm_1069470.pl $ cat pm_1069470.txt blah blah blah user=newvalue whatever user=something else user=newvalue other data

-- Ken


Comment on Re: Replace a string after a word
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1069534]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (12)
As of 2014-07-22 18:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (124 votes), past polls