using awk to print absolute value

Hi,
I have a file contaning some variables with negative values, but i just want to print the positive value

awk -F"|" '$2<0 { print $1,$2 }' tom.unl > tee.unl

i want the $2 = absolute value eg

-200 should print 200

How can i do this.

You could use a conditional expression.

$
$ awk 'BEGIN{x = -200; print x < 0 ? -x : x}'
200
$
$

tyler_durden

Maybe something like this?

awk -F"|" '{print $1, $2<0?$2*-1:$2}' file
1 Like