I have a text file which contains (among others) the following lines:
{chapter}{{1}Einleitung}{27}{chapter.1}
{chapter}{{2}Grundlagen}{35}{chapter.2}
How can I
- get the 2 lines from this text file (they will always contain
}Einleitung
resp.}Grundlagen}
and - extract the 2 page numbers (in this case 27 and 35),
- calculate the difference
35-27 = 8
and - save the difference (
8
) of the two numbers in a variable
Perhaps with a bash script in Mac OS X?
var=$({ grep -Eo '(Einleitung|Grundlagen)\}.[0-9]+.'|sort -r|tr '\n' ' '| tr -d -c '0-9 '|awk '{print $1 - $2}'; }</tmp/inputfile)