Created
December 13, 2022 18:58
-
-
Save dmd/f5a30a2efa8f0aaf72008e1247d53c99 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 | |
# Read the patterns from the file PATTERNS.txt and store them in an array | |
patterns=() | |
while IFS= read -r line; do | |
patterns+=("$line") | |
done < PATTERNS.txt | |
# Iterate over the patterns array and compare each pair of patterns | |
for ((i=0; i<${#patterns[@]}; i++)); do | |
for ((j=0; j<${#patterns[@]}; j++)); do | |
# Count the number of lines in TEXT.txt that contain both patterns as words | |
count=$(grep "\b${patterns[i]}\b.*\b${patterns[j]}\b" TEXT.txt | wc -l) | |
if (( $count > 0 )); then | |
echo "$count ${patterns[i]} ${patterns[j]}" | |
fi | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment