grep can search in multiple files, including those files recursively under a specified directory. This makes grep able to find which file contains a pattern.
Can awk and sed also? It seems that they can only process one file? Thanks.
From the awk FAQ:
16. How does awk deal with multiple files?
...
16.2 How can I get awk to read multiple files?
it's automatic (under Unix at least) -- use something like:<br /> <pre><code>awk '/^#include/ {print $2}' *.c *.h</code></pre></blockquote>
Awk will read from the files passed to it as arguments consecutively, ie., completing one before moving to the next. The name of the file being currently read is stored as
FILENAME
.This can be particularly useful when you are wanting to compare the contents of more than one file on a line-by-line (record by record) basis: such as in this question.
See the manual on reading files for a full explanation.
if you want to do it in a simple way , try using it along with foreach loop
foreach var (`ls directory_path`)
sed -i '/../.../ ' $var
awk '{ #commands to be run }' $var
end
shopt -s globstar; sed '...' **/*.txt
), else you can usefind
. – glenn jackman Aug 31 '14 at 01:31-s
flag to interepret multiple file args as separate streams – mikeserv Aug 31 '14 at 02:29-i
) to interact tothe file directly but is not the posix version – NeronLeVelu Sep 03 '14 at 08:26