Description
- Assume that the data file is sorted according to the first field.
It seems that grep will do this job well,
but consider a file which consists of 10000 lines and those lines
interesting you are the first 100 ones.
Although grep will print them out,
it will go on examining the remaining 9900 lines.
- In the following example, we use '70613' as PAT, and
the field separator is space.
|
| Raw Input
|
| Desired Output
| 7254 romans@abc.net
7254 stack@bcd.org
7254 giant@ab.cd.com
70613 mega@true.edu.tw
70613 meggy@false.com
70613 antims@msgotohell.cx
70613 blah@blah.bon.org
70613 ramma@comics.co.jp
enc gary@enc.com
enc devin@enc.com
enc roy@enc.com
|
| 70613 mega@true.edu.tw
70613 meggy@false.com
70613 antims@msgotohell.cx
70613 blah@blah.bon.org
70613 ramma@comics.co.jp
|
|
Script and Comments
Script1 [ 1] /^PAT /!d
[ 2] $!N
[ 3] /\nPAT /{
[ 4] P
[ 5] D
[ 6] }
[ 7] s/\n.*//
[ 8] q
| |