unix command to verify span of word in text
Posted
by
Ocasta Eshu
on Super User
See other posts from Super User
or by Ocasta Eshu
Published on 2012-06-27T02:14:15Z
Indexed on
2012/06/27
3:18 UTC
Read the original article
Hit count: 430
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!
© Super User or respective owner