Sample Header Ad - 728x90

Exclude file paths from a list based on contents of the files

-1 votes
1 answer
189 views
I have a command that I execute that gives me a list of relative paths to files under a directory. Think in terms of using find my_dir, although the command itself is different. For each file in the list, I want to pipe it into a command that will filter the list down depending on contents of the file itself. I'm looking for semantics identical or similar to egrep -v but it needs to open & read the file to run the regex on the file contents instead of the path itself. How can I accomplish this using a simple piped command stream? Example: find some_dir/ | egrep_contents -v 'Exclude pattern' | xargs -n1 do_something_with_filtered_files In this case, egrep_contents is ideally the command I'm asking for in this question. It would run the specified exclude pattern on each line in the file until it finds a match. If a match is found, it prevents that file path from being passed down to the next piped command. For context, I'm running these commands in Git Bash included with Git for Windows (MINGW).
Asked by void.pointer (355 rep)
Feb 28, 2020, 03:44 PM
Last activity: Feb 28, 2020, 06:04 PM