I am having some trouble using grep to output a list of phrases matching a pattern. For example I have a list of files with this format (separated by lines):
date:12/13/2012 name:foo time:10000
date:12/13/2012 name:bar time:20000
date:12/13/2012 name:hello time:30000
date:1/13/2012 name:foo time:40000
Ideally what I would want is just a file matching “name:foo” with an output like:
date:12/13/2012 name:foo time:10000
date:1/13/2012 name:foo time:40000
Is there a simple way of doing this? I am playing around with grep but I am having no success in getting desired output.
this recursively searches every file in the current folder and all subfolders for the phrase ‘name:foo’, and if it has been found on a specific line, print that line to output.txt
Is this what you wanted?
If the file the matching line is found in is of any importance, just remove the -h parameter and it will also print the file.