Home > Archive > AWK > April 2007 > help with regexp
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| giabernar@gmail.com 2007-04-07, 9:57 pm |
| Hi all,
i have a string like this:
List(coeffs,2.6911587353182782e11*pow(g,1/2) -
9.7637089664852677e8*pow(g,0.625) +
1.7711703797165706e6*pow(g,0.75) - 1882.1107192280536*pow(g,0.875)
+
1.*g,-2.1529103878556243e12*pow(g,1/2) +
5.8581802093492619e9*pow(g,0.625) -
7.0846268915887993e6*pow(g,0.75) + 3764.1924139800627*pow(g,
0.875));
I would like to add double quotes around the constants, for subsequent
processing, to have:
List(coeffs,"2.6911587353182782e11"*pow(g,1/2) -
"9.7637089664852677e8"*pow(g,0.625) +
"1.7711703797165706e6"*pow(g,0.75) - "1882.1107192280536"*pow(g,
0.875) +
"1."*g,-"2.1529103878556243e12"*pow(g,1/2) +
"5.8581802093492619e9"*pow(g,0.625) -
"7.0846268915887993e6"*pow(g,0.75) + "3764.1924139800627"*pow(g,
0.875));
I tried to match the constants with regular expressions but i failed.
Can someone suggest me the way to do this with awk?
Please help me.
Thanks in advance.
| |
| Vassilis 2007-04-07, 9:57 pm |
|
=CF/=C7 giabernar@gmail.com =DD=E3=F1=E1=F8=E5:
> Hi all,
> i have a string like this:
>
> List(coeffs,2.6911587353182782e11*pow(g,1/2) -
> 9.7637089664852677e8*pow(g,0.625) +
> 1.7711703797165706e6*pow(g,0.75) - 1882.1107192280536*pow(g,0.875)
> +
> 1.*g,-2.1529103878556243e12*pow(g,1/2) +
> 5.8581802093492619e9*pow(g,0.625) -
> 7.0846268915887993e6*pow(g,0.75) + 3764.1924139800627*pow(g,
> 0.875));
>
> I would like to add double quotes around the constants, for subsequent
> processing, to have:
>
> List(coeffs,"2.6911587353182782e11"*pow(g,1/2) -
> "9.7637089664852677e8"*pow(g,0.625) +
Do you want 0.625 quoted?
> "1.7711703797165706e6"*pow(g,0.75) - "1882.1107192280536"*pow(g,
> 0.875) +
0=2E875? And so on
> "1."*g,-"2.1529103878556243e12"*pow(g,1/2) +
> "5.8581802093492619e9"*pow(g,0.625) -
> "7.0846268915887993e6"*pow(g,0.75) + "3764.1924139800627"*pow(g,
> 0.875));
>
>
> I tried to match the constants with regular expressions but i failed.
>
> Can someone suggest me the way to do this with awk?
>
> Please help me.
>
> Thanks in advance.
Use this
{ gsub(/[0-9]+\.([0-9]+(e[0-9]+)?)?/, "\"&\""); print }
to quote any fractional number.
If there is more to it, be more specific.
Vassilis
| |
| giabernar@gmail.com 2007-04-08, 7:56 am |
| On 7 Apr, 20:54, "Vassilis" <F.H.Nova...@gmail.com> wrote:
> =CF/=C7 giaber...@gmail.com =DD=E3=F1=E1=F8=E5:
>
>
>
>
>
>
>
> Do you want 0.625 quoted?
>
>
> 0.875? And so on
>
>
>
>
>
>
> Use this
>
> { gsub(/[0-9]+\.([0-9]+(e[0-9]+)?)?/, "\"&\""); print }
>
> to quote any fractional number.
> If there is more to it, be more specific.
>
> Vassilis
Thanks very much, that was all i asked for.
|
|
|
|
|