Skip to main content
update with streamlined syntax and desc
Source Link
RobertL
  • 6.9k
  • 1
  • 22
  • 39

YouThis can use the fact that awk arrays are indexed by strings and thebe acomplished using two features of awk built-in variable FILENAME - the name of the current file.:

  1. arrays are indexed by strings
  2. the built-in variable FILENAME

This script assumes default field separators, and that blacklist.txt contains one field per line. Adjust according to your needs.

#!/bin/sh

awk '
    {
        if (FILENAME == "blacklist.txt") {
            blacklist[$0] = 1
        }next
        else {}
            if (blacklist[$4]) {
                print $4, $0
            }
        }
    }
' blacklist.txt -

You can use the fact that awk arrays are indexed by strings and the awk built-in variable FILENAME - the name of the current file.

This assumes default field separators, and that blacklist.txt contains one field per line. Adjust according to your needs.

#!/bin/sh

awk '
    {
        if (FILENAME == "blacklist.txt") {
            blacklist[$0] = 1
        }
        else {
            if (blacklist[$4]) {
                print $4, $0
            }
        }
    }
' blacklist.txt -

This can be acomplished using two features of awk:

  1. arrays are indexed by strings
  2. the built-in variable FILENAME

This script assumes default field separators, and that blacklist.txt contains one field per line. Adjust according to your needs.

#!/bin/sh

awk '
    FILENAME == "blacklist.txt" {
        blacklist[$0] = 1
        next
    }
    blacklist[$4] {
        print $4, $0
    }
' blacklist.txt -
Source Link
RobertL
  • 6.9k
  • 1
  • 22
  • 39

You can use the fact that awk arrays are indexed by strings and the awk built-in variable FILENAME - the name of the current file.

This assumes default field separators, and that blacklist.txt contains one field per line. Adjust according to your needs.

#!/bin/sh

awk '
    {
        if (FILENAME == "blacklist.txt") {
            blacklist[$0] = 1
        }
        else {
            if (blacklist[$4]) {
                print $4, $0
            }
        }
    }
' blacklist.txt -