In a script, I want to find files that contain some text. I need to know the file the text is found in, and the full line within the file that the text is found in. grep
is the utility that does this, but how can I get the output into a usable form, given that there can be :
in filenames? Is there some sort of --porcelain
mode for grep
that I can use, kinda like git
commands often have?
Example: I have a folder full of files named like test-num:1:date:jan-2
that I want to grep through. The files contain FAILURE:<some reason>
or SUCCESS:<some reason>
(among other stuff). I need a script that searches for certain reasons and stores the name of the file, and the reason (the whole line of text is fine) for later processing. The output can be in any sort of data structure, as long as I can run code over it.
-Z
option that inserts a null byte instead – steeldriver Oct 31 '16 at 10:54awk 'commands go here' somedirectory/*
, you can check for patterns, you can print filenames directly, etc. But without the sample chunk and sample output as @heemayl requested it's hard to give any better solution. – Wildcard Nov 1 '16 at 2:02