Created
December 5, 2023 15:21
-
-
Save jeansymolanza/f151a5fd050618bd9af238b5e36ea6dc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
num_threads=<num_threads> | |
pattern_file="pattern_list.txt" | |
output_file="output.txt" | |
directory_path="directory_path" | |
# Read each pattern from the pattern file | |
while IFS= read -r pattern; do | |
# Run grep in the background for each pattern | |
grep -r -n "$pattern" "$directory_path" >> "$output_file" & | |
# Limit the number of concurrent background processes | |
if [[ $(jobs -p | wc -l) -ge $num_threads ]]; then | |
wait -n | |
fi | |
done < "$pattern_file" | |
# Wait for any remaining background processes to finish | |
wait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment