I want to grep multiple files in a directory and collect the output of each grep in a separate file ..So if I grep 20 files, I should get 20 output-files which contain the searched item. Can anybody help me with this? Thanks.
+6
A:
Use a for
statement:
for a in *.txt; do grep target $a >$a.out; done
Greg Hewgill
2009-11-25 21:32:11
thanks lot for the quick reply :-)
Sharat Chandra
2009-11-25 21:37:20
+1
A:
just one gawk command
gawk '/target/ {print $0 > FILENAME".out"}' *.txt
ghostdog74
2009-11-26 00:03:02