Skip to main content
Added missing r
Source Link
Freddy
  • 26.3k
  • 1
  • 27
  • 64

Not exactly a single command, but:

num_patterns=$( wc -l < patterns_file )
for file in dir/*; do
    num_occurrances=$( grep -F -o -f patterns_file "$file" | sort -u | wc -l )
    if (( num_patterns == num_occurancesnum_occurrances )); then
        echo "all patterns in $file"
    fi
done

This approach won't work when the patterns are regular expressions, because the matching text probably won't be unique for every match.

Not exactly a single command, but:

num_patterns=$( wc -l < patterns_file )
for file in dir/*; do
    num_occurrances=$( grep -F -o -f patterns_file "$file" | sort -u | wc -l )
    if (( num_patterns == num_occurances )); then
        echo "all patterns in $file"
    fi
done

This approach won't work when the patterns are regular expressions, because the matching text probably won't be unique for every match.

Not exactly a single command, but:

num_patterns=$( wc -l < patterns_file )
for file in dir/*; do
    num_occurrances=$( grep -F -o -f patterns_file "$file" | sort -u | wc -l )
    if (( num_patterns == num_occurrances )); then
        echo "all patterns in $file"
    fi
done

This approach won't work when the patterns are regular expressions, because the matching text probably won't be unique for every match.

Missing quote
Source Link
Kusalananda
  • 355.9k
  • 42
  • 735
  • 1.1k

Not exactly a single command, but:

num_patterns=$( wc -l < patterns_file )
for file in dir/*; do
    num_occurrances=$( grep -F -o -f patterns_file $file""$file" | sort -u | wc -l )
    if (( num_patterns == num_occurances )); then
        echo "all patterns in $file"
    fi
done

This approach won't work when the patterns are regular expressions, because the matching text probably won't be unique for every match.

Not exactly a single command, but:

num_patterns=$( wc -l < patterns_file )
for file in dir/*; do
    num_occurrances=$( grep -F -o -f patterns_file $file" | sort -u | wc -l )
    if (( num_patterns == num_occurances )); then
        echo "all patterns in $file"
    fi
done

This approach won't work when the patterns are regular expressions, because the matching text probably won't be unique for every match.

Not exactly a single command, but:

num_patterns=$( wc -l < patterns_file )
for file in dir/*; do
    num_occurrances=$( grep -F -o -f patterns_file "$file" | sort -u | wc -l )
    if (( num_patterns == num_occurances )); then
        echo "all patterns in $file"
    fi
done

This approach won't work when the patterns are regular expressions, because the matching text probably won't be unique for every match.

Source Link
glenn jackman
  • 88.5k
  • 16
  • 124
  • 179

Not exactly a single command, but:

num_patterns=$( wc -l < patterns_file )
for file in dir/*; do
    num_occurrances=$( grep -F -o -f patterns_file $file" | sort -u | wc -l )
    if (( num_patterns == num_occurances )); then
        echo "all patterns in $file"
    fi
done

This approach won't work when the patterns are regular expressions, because the matching text probably won't be unique for every match.