grep the line contains only the match
grep the line contains only the match
I have the below file for example,
Hello world cheers
Hello world
Hi Hello world
Hi Hello world, How are you?
I would like to grep the line which contains only the Hello world
with the line number.
Hello world
@Kusalananda .. Thanks...as of now, i have requirement only to log these details.
– fini r
2 days ago
stackoverflow.com/questions/4709912/…
– Julien Lopez
2 days ago
Possible duplicate of grep to fetch whole line
– roaima
13 hours ago
1 Answer
1
Try this,
grep -nx "Hello world" fileName
-n
-x
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
How will you be using the line number later? If you are going to extract or change the line by its line number, then it's better to do so in one go instead of calling two utilities in sequence (getting the line number, then do something with that line).
– Kusalananda
2 days ago