Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: to copy certain content in file & repeat it .

by davido (Cardinal)
on Jun 30, 2011 at 06:23 UTC ( [id://912101]=note: print w/replies, xml ) Need Help??


in reply to to copy certain content in file & repeat it .

perl -pi.bak -07d -e 's/(hero\{.*)/$1 . 'copy_' . $1/es;' filename.txt

Untested. It should set the input record separator to the '}' character, and then finding the start tag it subs everything between start and end tags with a second copy, and makes a backup just in case I got it entirely wrong. ;)

The /e isn't strictly necessary, but it allowed me to make the right hand side of the s/// operator easier to read.


Dave

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (9)
As of 2024-04-23 11:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found