How do I subtract the value of column 2 of one row with the value of column 3 of the previous row and print the result in a new row in bash.
I tried with awk like this, but I miss the part to change the line
awk '{a=$3; b=$2; c=a-b;print $0,c;}' input.bed
The input is:
NC_048323.1 21 29
----------------------
NC_048323.1 62 65
----------------------
NC_048323.1 128 179
--------------------
NC_048323.1 204 238
--------------------------
NC_048323.1 296 392
--------------------------
NC_048323.1 427 448
---------------------------
NC_048323.1 477 507
---------------------------
My desired output then is:
NC_048323.1 21 29 21
---------------------------------
NC_048323.1 62 65 33
---------------------------------
NC_048323.1 128 179 63
---------------------------------
NC_048323.1 204 238 25
---------------------------------
NC_048323.1 296 392 58
---------------------------------
NC_048323.1 427 448 35
---------------------------------
NC_048323.1 477 507 29
---------------------------------