walala wrote:
....
> I want to search and replace some string in input file A.txt and then output
> B.txt.
>
>
> The target string in A.txt is:¡°NRD=1U/X.XXE-0X¡±,(where X.XX stands for a
> number, -E0X is its exponentials, for example, NRD=1U/1.84E-06)
>
> I want to change this to ¡°NRD=Y.YYYY¡±, where Y.YYYY=1e-6/X.XXe-0X.
>
> For example, "NRD=1U/1.84E-06" -> "NRD=0.5435
>
> I want to search the whole file and for all such occurence, replace then
> output to B.txt.
>
> Can anybody give me the example code on how to do this? Thanks a lot!
>
> -Walala
One one line [untested]:
perl -pe
's|NRD=1U/(\d\.\d\dE[+-]?0\d)|"NRD=".sprintf("%6.4f",1e-6/$1)|eg' A.txt
>B.txt
Change quotes around if on Windoze.
--
Bob Walton
|