Skip to content
Advertisement

How to get absolute value after subtracting the following value by the previous value in a file with multiple colomns?

I have a file contains numbers.

1 34 44 44 46

5 35 40 40 45

6 36 28 30 40

My goal is for each column to have the absolute value after subtracting the following value by the previous one as the below:

1 34 44 44 46

4 1 4 4 1

1 1 12 10 5

I used

JavaScript

but I got only the absolute value of the subtractions of the first column. I tried also the $0 instead of $1 but i didn’t get the correct output. Does anyone has an idea how to improve the above command in order to get my desired output?

Advertisement

Answer

test.awk

JavaScript

run as follows:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement