470,849 Members | 1,383 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

Processing and adding numbers from lines.

Hello, Group:

Is there an easy way to automate the processing of adding the following
numbers in two lines?

test test test description (100-10-0, 6700 test)
test test test description (100-10-0, 6350 test)

I'd like to be able run a script on the file above to produce the
following results.

200-20 .9090

The lines will stay the same, but the numbers will change. I'd like to
be able copy and paste the lines into an html form to process the
results.

Regards,

--SF

Jan 5 '06 #1
6 1208
NC
sa*********@gmail.com wrote:

Is there an easy way to automate the processing of adding the following
numbers in two lines?

test test test description (100-10-0, 6700 test)
test test test description (100-10-0, 6350 test)
Yes. You can get all numbers out of the string using regular
expressions or a simple explode()...
I'd like to be able run a script on the file above to produce the
following results.

200-20 .9090


How do you arrive at .9090?

Cheers,
NC

Jan 5 '06 #2
NC:

..90 is the percent that 20 is of 220. Do you have a sample that might
lead me the right direction? I'm not very good with regular expersions
that involve processing lines with data the needs to be thrown out.

--SF

Jan 5 '06 #3
NC:

..90 is the percent that 20 is of 220. Do you have a sample that might
lead me the right direction? I'm not very good with regular expersions
that involve processing lines with data the needs to be thrown out.

--SF

Jan 5 '06 #4
NC:

..90 is the percent that 20 is of 220. Do you have a sample that might
lead me the right direction? I'm not very good with regular expersions
that involve processing lines with data the needs to be thrown out.

--SF

Jan 5 '06 #5
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

sa*********@gmail.com wrote:
Is there an easy way to automate the processing of adding the following
numbers in two lines?

test test test description (100-10-0, 6700 test)
test test test description (100-10-0, 6350 test)


sscanf.

- --
- ----------------------------------
Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

Por su pico, se pierde el pajarico.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFDvY3f3jcQ2mg3Pc8RAvk8AJ9oiEgHNFkkqMMsp6PFmd jpJhAekgCfYvXH
WWxL9mLBW8f/Ync6nnycSgo=
=ffC7
-----END PGP SIGNATURE-----
Jan 5 '06 #6
NC
sa*********@gmail.com wrote:

.90 is the percent that 20 is of 220.
Not really... 20 is 9.090909...% of 220...
Do you have a sample that might lead me the right direction?


Let's see...

$line1 = 'test test test description (100-10-0, 6700 test)';
$line2 = 'test test test description (100-10-0, 6350 test)';
list(, $temp) = explode('(', $line1);
list($temp,) = explode(',', $temp);
list($n11, $n12, $n13) = explode('-', $temp);
list(, $temp) = explode('(', $line2);
list($temp,) = explode(',', $temp);
list($n21, $n22, $n23) = explode('-', $temp);
echo $n11+$n21, '-', $n12+$n22, ' ',
number_format(1-($n12+$n22)/($n11+$n21+$n12+$n22),4);

That's it, really...

Cheers,
NC

Jan 6 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

23 posts views Thread by Daniel Rudy | last post: by
6 posts views Thread by Hareth | last post: by
1 post views Thread by sanfranc415 | last post: by
17 posts views Thread by Sri | last post: by
60 posts views Thread by Bill Cunningham | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.