0
0
I would like to print and substract in each two rows from a file
toto 30
tata 20
toto 12
tata 6
toto 22
tata 8
the output :
diff : 10
diff : 6
diff : 14
I find a script :
FILENAME=$1
while read line
do
if [ -n "$prevLine" ]
then
curLine=$line
echo $(($curLine - $prevLine))
fi
prevLine=($line)
done < $FILENAME
I would like to read line+1 to make a range of 2
1You will need to read the file using a loop. – FedonKadifeli – 2019-07-16T13:49:40.113
Your script is on the right lines. Add a line counter which is incremented on each loop pass and check whether
$(($lineNo%2))
is zero to decide when difference is to be calculated and printed. – AFH – 2019-07-16T14:00:53.510I don't understand you solution, Can you have a code to propose me ? – tumareure – 2019-07-16T14:03:26.197