cat and grep
Hello Friends,
I want to cat and grep some files and redirect the output to an output file. The problem is I am having lots of files to check, so I have put all the file paths in a text file paths.txt. I want cat to pick up paths one by one from paths.txt and check, not sure how to pick up one by one path from the file. I don't have much scripting knowledge. Please help me in this case. Thanks & Regards, Dipu |
Try something like this
for i in `cat ~/list_of _files`; do grep filter-text $i ; done |
Quote:
Code:
for i in $(< /path/to/file) "cat" Forks another process which slows your script down a bit. Remember... Quote:
|
Quote:
|
Quote:
That's what I like about *nix systems...so many ways to do the same thing :) -C |
Amazing response guys!! Thanks a lot. I got to learn bash scripting now.
I tried both the ways and all worked fine. But all what I am getting is a list of filter-text(the keyword i searched), so I am unable to determine which file contains the filter-text and which doesn't. Kindly help me with that. Here's why I want so- I need to grep all dns zone files on dns server to check which one contains "spf" record and which doesn't. Thanks and Regards, Dipu |
Quote:
|
Maybe something like this....?
Code:
#/bin/bash -C |
In your case of looping over files you just the exit value and one instance per file suffices: "for item in list; do grep -i spf -m1 -q item && echo SPF record". OTOH w/o looping "grep -i spf -l -r /path/to/dir" returns all filenames containing the case-insensitive term "spf" just fine.
|
Quote:
-C |
Quote:
|
Quote:
I got errors with this script. The error is like: filename : line 7 : spf: integer expression expected. filename : line 7 : [: -ge: unary operator expected However my requirement is fulfilled now!! I used the below command (as I needed the files which does not contain spf) grep -r -L spf /path/to/directory Thanks a lot to everyone. |
All times are GMT -5. The time now is 10:28 AM. |