I have a file containing one column of number:
1
2
4
4
10
I would like to calculate the difference between each number using awk. The output should be like this :
1
2
0
6
How can I do it ?
See Question&Answers more detail:osI have a file containing one column of number:
1
2
4
4
10
I would like to calculate the difference between each number using awk. The output should be like this :
1
2
0
6
How can I do it ?
See Question&Answers more detail:osTry the following code :
awk '
NR == 1{old = $1; next} # if 1st line
{print $1 - old; old = $1} # else...
' file.txt
1
2
0
6