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?? |
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
In Section
Seekers of Perl Wisdom
|
|