Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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' *.c

but 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
generic float dbl long cfloat c dbl cmplx long atanh atanhf atanh atanhl catanhf catanh catanhl

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
perl -pi -e 's/c$tgt || c$tgtf || c$tgtl || $tgtf || $tgtl /$tgt/g' *. +c

where $tgt is the replacement string, for example

$tgt = tanh

i need to search and replace the following

tanhf  tanhl ctanhf ctanh ctanhl

but 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

exa=cexpl ( ccosl (arg), csinl ( arg) ) * cabsl (arg2) + csqrtl ( carg +l(arg3) + csqrtl(cargl(arg4) * cargl(arg5) + cargl (arg5) * cargl(arg +5));
result would be
exa = exp( cos(arg) , sin(arg) ) * fabs(arg2)+ sqrt(carg(arg3) + sqrt( +carg(arg4)*carg(arg5)+carg(arg5)*carg(arg5));

In reply to search/replace one liners without clobbering by f77coder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2021-11-28 23:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?