Tuesday, September 09, 2008

to show multi line around grep result

You can grep multiple lines before or after matching the keywords. Here is a simple tips, that what I discover grep capable of. A is after, B is before.

For example, test.data is like this:

ENSG00000007372 ENSG00000109911 ENSG00000121690
ENSG00000007372 ENSG00000149100 ENSG00000170959
ENSG00000043355 ENSG00000175198 ENSG00000102452
ENSG00000172845 ENSG00000115840 ENSG00000091428
ENSG00000172845 ENSG00000138430 ENSG00000128708
ENSG00000103449 ENSG00000103494 ENSG00000121274
ENSG00000104313 ENSG00000182674 ENSG00000140396
ENSG00000117707 ENSG00000136643 ENSG00000143499
ENSG00000121297 ENSG00000105176 ENSG00000178904

>grep ENSG00000138430  test.data 
ENSG00000172845 ENSG00000115840 ENSG00000091428

while,
>grep ENSG00000138430  test.data -B1 -A3
ENSG00000172845 ENSG00000115840 ENSG00000091428
ENSG00000172845 ENSG00000138430 ENSG00000128708
ENSG00000103449 ENSG00000103494 ENSG00000121274
ENSG00000104313 ENSG00000182674 ENSG00000140396
ENSG00000117707 ENSG00000136643 ENSG00000143499

No comments:

Post a Comment