3
What unix command(s) can I use to determine the line span that a word appears in text? The "span" being equal to the line number of the last instance of a word minus the line number of the first instance of the word.
1| unix is on two lines
2| once above, and once below
3| unix
In the example above the "span" of 'unix' would be 2 (3-1).
So far I've been trying to make use of grep -n but I don't think that grep is powerful enough. Maybe some use of sed or awk?
Thanks!
1Althoug I already answered. The
span
will be 2 because there are two lines in which the unix word appear or because the unix word apears two times in the same line? – fmanco – 2012-06-27T02:20:01.957Span = (last line with 'unix' - first line with 'unix') so because 'unix' appears on lines 1,2,3 (or 0,1,2 if you prefer) 3-1 equals 2 (or again 2-0=2), so the "span" is 2. Sorry that wasn't clear. – Ocasta Eshu – 2012-06-27T02:45:36.167
Post edited for clarity. – Ocasta Eshu – 2012-06-27T02:55:01.303