0

I have a text file with 3 columns of data. However at random times in the various files there is a change in the in the observed unit from ppn to ppb resulting in the need of a conversion factor and multiplication by 1000.

actual data                        needed data look
20101001,01:00,0.3                 20101001,01:00,0.3,300.000
20110103,10:00,212.67              20110103,10:00,212.670,212.670

I have a awk command to print all original and add a fourth column with the conversion.

The only issue is it prints everything everything in the third column by 1000 and print to the fourth column. The command is below....

awk -F ',' '{printf "%s %s %.3f %.3f\n", $1,$2,$3,$3*1000}' temp7.tmp > County001-CO-0012.out

How can I can only values between 2 and -1 in column #3 only get multiplied by 1000 and other wise print the orignal value of column 3 in column 4?

0

1 Answer 1

2

You can do this in the awk code:

{
    # if $3 is between -1 and 2, multiply by 1000
    converted = $3 * (-1 <= $3 && $3 <= 2 ? 1000 : 1)
    printf "%s %s %.3f %.3f\n", $1, $2, $3, converted
}

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.