AWK processing -numbers to another column

Hi Guys,

I'm trying to clean up my home logger file and can't seem to work this out.

Here is my data:

10-19-2009 08:39 00.2 00.0 00.7 01.1 49.1 0.0 11.9 270.1 -49.1 220.9
10-19-2009 08:40 00.2 00.0 00.7 00.7 49.1 0.0 171.9 171.9 49.1 220.9
10-19-2009 08:41 00.1 00.0 00.7 00.8 24.5 0.0 171.9 196.4 0.0 196.4
10-19-2009 08:42 00.1 00.0 00.7 00.8 24.5 0.0 171.9 196.4 0.0 196.4
10-19-2009 08:43 00.1 00.0 00.6 00.8 24.5 0.0 147.3 196.4 -24.5 171.9
10-19-2009 08:44 00.4 00.0 00.6 00.9 98.2 0.0 147.3 220.9 24.5 245.5

What I'm trying to do is that the $11 column needs to replaced with 0.0 if it is negative. Then the negative number needs to go in a new column $13 as a positive. Otherwise if nothing needs to be changed, like the second row, 0.0 should be added to $13.

so for example the top two line should end up looking like this after processing:

10-19-2009 08:39 00.2 00.0 00.7 01.1 49.1 0.0 11.9 270.1 0.0 220.9 49.1
10-19-2009 08:40 00.2 00.0 00.7 00.7 49.1 0.0 171.9 171.9 49.1 220.9 0.0

Thanks for any help!

Bj

Hi BeJay, Is this what you mean?

awk '{if ($11<0) {$13=-$11; $11="0.0"} else $13="0.0"} 1' infile

output:

10-19-2009 08:39 00.2 00.0 00.7 01.1 49.1 0.0 11.9 270.1 0.0 220.9 49.1
10-19-2009 08:40 00.2 00.0 00.7 00.7 49.1 0.0 171.9 171.9 49.1 220.9 0.0
10-19-2009 08:41 00.1 00.0 00.7 00.8 24.5 0.0 171.9 196.4 0.0 196.4 0.0
10-19-2009 08:42 00.1 00.0 00.7 00.8 24.5 0.0 171.9 196.4 0.0 196.4 0.0
10-19-2009 08:43 00.1 00.0 00.6 00.8 24.5 0.0 147.3 196.4 0.0 171.9 24.5
10-19-2009 08:44 00.4 00.0 00.6 00.9 98.2 0.0 147.3 220.9 24.5 245.5 0.0

That is perfect Scrutinizer :b:

I didn't know you could use if/then statements in AWK, so that makes it much easier to understand. I've been bashing my head for quite a while :confused:

Thanks again!

Bj