# [CentOS] Conversion of text in shell

Ross S. W. Walker rwalker at medallion.com
Sat Oct 13 00:06:50 UTC 2007

Ross S. W. Walker
>
> Ross S. W. Walker wrote:
> >
> > roland hellström wrote:
> > >
> > > OK! I finally figured out the solution for all you people out
> > > the eager to hear it!!!
> > > it was infact very very similar to the last line I sent...
> > this is it
> > > sed 's/$$[^\.]*$$.$$[^,]*$$,$$[^\.]*$$.$$[^e]*$$e$$.*$$/\1,\2
> > > \& $\3,\4 \\cdot 10^{\5}$\\\\/'
> > >
> > > omg I feel so h4xx0r figuring that out myself lol
> > > Thx for the help all :)
> >
> > I am surprised you got it all in 1 regex, I was aiming more for:
> >
> > sed 's/,/ & /;s/\./,/;s/$$.*$$e$$.*$$/\1 \\cdot 10^{\2}/'
>
> whoops, I made a mistake:
>
> sed 's/,/ \& /;s/\./,/g;s/$$.*$$e$$.*$$/\1 \\cdot 10^{\2}\$\\\\/' > > You need the 'g' option in the second substitute to perform a > global, and of course the proper cdot expression. Ok, not to toot my own horn, but it turns out that doing 3 simple regexs is actually quicker then 1 complex regex, though with today's processors you need to run it over a large set to see: # wc -l test 20691 test # time sed 's/$$[^\.]*$$.$$[^,]*$$,$$[^\.]*$$.$$[^e]*$$e$$.*$$/\1,\2 \&$\3,\4 \\cdot 10^{\5}$\\\\/' test >/dev/null real 0m0.175s user 0m0.174s sys 0m0.000s # time sed 's/,/ \& \$/;s/\./,/g;s/$$.*$$e$$.*$$/\1 \\cdot 10^{\2}\\$\\\\/' test >/dev/null

real    0m0.141s
user    0m0.139s
sys     0m0.001s

So not only is it simpler to divide and conqueror a problem, but
often it produces the best results...

-Ross

______________________________________________________________________
This e-mail, and any attachments thereto, is intended only for use by
the addressee(s) named herein and may contain legally privileged
and/or confidential information. If you are not the intended recipient
of this e-mail, you are hereby notified that any dissemination,
distribution or copying of this e-mail, and any attachments thereto,
is strictly prohibited. If you have received this e-mail in error,
please immediately notify the sender and permanently delete the
original and any copy or printout thereof.