Just another Perl shrine | |
PerlMonks |
search/replace one liners without clobberingby f77coder (Beadle) |
on Feb 25, 2016 at 22:50 UTC ( [id://1156148]=perlquestion: print w/replies, xml ) | Need Help?? |
f77coder has asked for the wisdom of the Perl Monks concerning the following question:
Hello,
I need a bit of help, usually for bulk replacement of a word in a bunch of files I do something like this perl -pi -e 's/junk/replace/g' *.cbut i need to be able to put a conditional || on the search without clobbering, I'm updating old C files to C11 type generic. there are a lot of type specific qualifiers that i want to replace with generic http://en.cppreference.com/w/c/numeric/tgmath for example
so in general i need to check for suffixes and prefixes at the same time otherwise the search term will clobber the previous search. i need to put a conditional in the search like this
where $tgt is the replacement string, for example
i need to search and replace the following tanhf tanhl ctanhf ctanh ctanhlbut i get a complete mess out as the command still recurses and substitutes. as well as the tricky one to replace 'rint' as it will conflict with printf these old files have no spaces between operators but i'll space it out result would be
Back to
Seekers of Perl Wisdom
|
|