If anybody can help me to find out and answer for following case, it would be much appreciated. I need a solution which should be able to execute in bash shell
.
Suppose I have file like this,
1.Mary had a little lamb,
2.Little lamb, little lamb,
3.Mary had a little lamb,
4.Its fleece was white as snow
5.And everywhere that Mary went,
6.Mary went, Mary went,
7.Everywhere that Mary went
8.The lamb was sure to go
9.It followed her to school one day
10.School one day, school one day
11.It followed her to school one day
12.Which was against the rules.
My search criteria is like this,
It should first search for word little
(i.e. line 1 2 and 3) and in the next row there should be a word fleece
(i.e. line 4 only) the output should print two matching lines (3 and 4) plus four lines after last searched line which is by fleece
at line number 4. So final output should be lines 3,4,5,6,7,8
Solution could be a bash shell script, perl or python.
Please share your ideas.