3

I use this command

awk 'NR%2{t=$1;next}{print $1-t,$2}'

to get the distance between two consecutive Y points in a file. But I would like to have all positive numbers. How to get that ? like something as modulus.

1577 -46.1492
1577.57 47
1578 -47.6528
1578.87 49
1579 -49.2106
1580 -50.7742
1580.15 51

closed as unclear what you're asking by Kusalananda, jimmij, msp9011, Jeff Schaller, Anthony Geoghegan Mar 25 at 15:12

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    It is unclear (as you can see from the answers) whether the data that you present is input to your existing awk script or output from it. – Kusalananda Mar 25 at 9:47
2
Command: awk '$2 !~ /^-/{print $0}' file

output

1577.57 47
1578.87 49
1580.15 51
3

You can replace this:

{print $1-t,$2}

with this:

{if ($2>=0) print $1-t,$2}

or,

$2 >= 0 { print $1 - t, $2 }

Not the answer you're looking for? Browse other questions tagged or ask your own question.