Unix/Linux Go Back    

Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Perl:: mass replacement of converting C code formats to tgmath.h

Shell Programming and Scripting

perl, prefix, replace a string, solved, suffix

Thread Tools Search this Thread Display Modes
Old Unix and Linux 02-25-2016   -   Original Discussion by f77hack
f77hack's Unix or Linux Image
f77hack f77hack is offline
Registered User
Join Date: Jan 2016
Last Activity: 16 April 2018, 10:03 PM EDT
Location: 3rd planet
Posts: 32
Thanks: 27
Thanked 1 Time in 1 Post
Perl:: mass replacement of converting C code formats to tgmath.h


i have a lot of C old code I'm updating to C11 with tgmath.h for generic math. the old code has very specific types, real and complex, like cabsl, csinhl, etc

usually for simple bulk replacements i would do something simple like this

perl -pi -e 's/cosl/cos/g' *.c

the reference is here
HTML Code:

real complex
generic float long dble dble dble float long dble dble dble
fabs fabsf fabs fabsl cabsf cabs cabsl
exp expf exp expl cexpf cexp cexpl
log logf log logl clogf clog clogl

there are basically two classes of operations

array=(fabs exp log pow sqrt sin cos tan acos atan sinh cosh tanh asinh acosh atanh)
for tgt in array
perl -pi -e 's/${tgt}f/${tgt}/g' *.*
perl -pi -e 's/${tgt}l/${tgt}/g' *.*
perl -pi -e 's/c${tgt}/${tgt}/g' *.*
perl -pi -e 's/c${tgt}f/${tgt}/g' *.*
perl -pi -e 's/c${tgt}l/${tgt}/g' *.*
#special case of fabs
perl -pi -e 's/cabs/${tgt}/g' *.*


array=(atan2 cbrt ceil copysign erf erfc exp2 expm1 fdim floor fma fmax fmin fmod)
array+=(frexp hypot ilogb ldexp lgamma llrint llround log10 log1p log2 logb lrint)
array+=(lround nearbyint nextafter nexttoward remainder remquo rint roiund scalbin)
array+=(scalbn tgamma trunc carg conj creal cimag cproj)
for tgt in array
perl -pi -e 's/${tgt}f/${tgt}/g' *.*
perl -pi -e 's/${tgt}l/${tgt}/g' *.

perl is not mandatory, but a sweet one or two liner would be excellent.


---------- Post updated at 04:36 PM ---------- Previous update was at 02:55 PM ----------

oh well, i went ahead my own my loops and forked.

Last edited by f77hack; 02-25-2016 at 03:30 PM.. Reason: typo
Sponsored Links

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Block of code replacement in Java source code through Unix script hareeshram Shell Programming and Scripting 2 01-30-2012 10:54 AM
Converting date string to different formats GermanJulian Shell Programming and Scripting 6 05-13-2010 10:05 AM
Passing date formats in Perl: i.e. Jul/10/2007 -> 20070710 (yyyymmdd) - Perl akil Shell Programming and Scripting 7 07-17-2009 09:09 AM
Converting Perl code to shell zainravi Shell Programming and Scripting 8 03-12-2009 12:54 PM
VI questions : mass changes, mass delete and external insert Browser_ice AIX 1 12-13-2006 03:20 AM

All times are GMT -4. The time now is 03:20 AM.