Eg- lets suppose I want to grep string VR030315ITVENDMXN
. Then grep should not show VR030315ITVENDMXN-LPP
or any additional things with VR030315ITVENDMXN
.
Asked
Active
Viewed 434 times
-2

tomrozb
- 25,773
- 31
- 101
- 122
-
1please indicate some sample input and desired output, it is not very clear what you mean. Exact match or just print the match? – fedorqui Mar 10 '15 at 11:03
2 Answers
0
You need to use the -o (or --only-matching ) option in your command line option
Of you do not desire to have the filename displayed use the -h (--no-filename) option in addition to remove them.

dvhh
- 4,724
- 27
- 33
-
$ grep --o "VR030315ITVENDMXN" * LCDE.BLQSAM.OCAA2441.C0368800.B5C03O54:VR030315ITVENDMXN LCDE.BLQSAM.OCAA2441.C0368802.B5C03Q32:VR030315ITVENDMXN LCDE.BLQSAM.XMXA2441.C0368801.B5C03O55:VR030315ITVENDMXN LCDE.BLQSAM.XMXA2441.C0368801.B5C03O55:VR030315ITVENDMXN LCDE.BLQSAM.XMXA2441.C0368803.B5C03Q34:VR030315ITVENDMXN LCDE.BLQSAM.XMXA2441.C0368803.B5C03Q34:VR030315ITVENDMXN – Nilay Mishra Mar 10 '15 at 11:12
-
Thanks for your reply. But I have tried below commands but no luck. :( $ grep -o 'VR030315ITVENDMXN' * LCDE.BLQSAM.OCAA2441.C0368800.B5C03O54:VR030315ITVENDMXN LCDE.BLQSAM.OCAA2441.C0368802.B5C03Q32:VR030315ITVENDMXN LCDE.BLQSAM.XMXA2441.C0368801.B5C03O55:VR030315ITVENDMXN LCDE.BLQSAM.XMXA2441.C0368801.B5C03O55:VR030315ITVENDMXN LCDE.BLQSAM.XMXA2441.C0368803.B5C03Q34:VR030315ITVENDMXN LCDE.BLQSAM.XMXA2441.C0368803.B5C03Q34:VR030315ITVENDM – Nilay Mishra Mar 10 '15 at 11:14
-
so it is the exact hit but with the filename and the line number location – dvhh Mar 10 '15 at 13:04
0
Can you use anchors? For instance:
grep '^VR030315ITVENDMXN$' file
There is a similar question here How to make grep only match if the entire line matches?

Community
- 1
- 1

Danilo Gomes
- 571
- 6
- 13