Howdy,
I've been doing my nut in for a while now, trying to extract two lines of
text from a file. I've unsuccessfully tried many grep and sed options, to
no avail. Eventually I used grep -C 2 <Regexp> <file> to get the lines I
wanted. That was primarily because the lines I wanted happened to closely
located. Below (1) is an example of the file I'm grep'ing. I'm only
looking for the lines with "Distance:..."and "1., Trap...".
How can I use grep to extract only those lines without using the -C
option? To get for example "Distance:..." and "2.,Trap ..."?
TIA for any suggestions, R
(1)
<Example of text to grep>
Race 1
Distance:,375 yds.
1.,Trap 6 ,SPUR ON,,75,,21.17, 4/1
2.,Trap 2 ,PLAYFIELD MOIRA,,63,1L,21.24, 4/5
3.,Trap 4 ,ALL SEASONS,, 61,3.5L,21.48, 5/1,
4.,Trap 5 ,KNOCKLEE ANNIE,, 57,0.75L,21.54, 2/1,
5.,Trap 1 ,SIONNAINS WAY,, 63,6L,21.96, 3/1
6.,Trap 3 ,LASS DECISION,, 57,2L,22.10, 5/1
</Example of text to grep>
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!