# Processing and adding numbers from lines.

#### Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on
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

## Re: Processing and adding numbers from lines.

sanfranc415@gmail.com wrote:

Yes.  You can get all numbers out of the string using regular
expressions or a simple explode()...

How do you arrive at .9090?

Cheers,
NC

## Re: Processing and adding numbers from lines.

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

## Re: Processing and adding numbers from lines.

sanfranc415@gmail.com wrote:

Not really... 20 is 9.090909...% of 220...

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

## Re: Processing and adding numbers from lines.

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

## Re: Processing and adding numbers from lines.

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

## Re: Processing and adding numbers from lines.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

sanfranc415@gmail.com wrote:

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)

iD8DBQFDvY3f3jcQ2mg3Pc8RAvk8AJ9oiEgHNFkkqMMsp6PFmdjpJhAekgCfYvXH
WWxL9mLBW8f/Ync6nnycSgo=
=ffC7
-----END PGP SIGNATURE-----