I have a pipe delimited file





I am trying to get the value of Yellow present In File.txt to the exact match from pipe delimited file I.e Lookup.txt. The output should be the entire line as shown below. File.txt file are having the values to search in the file Lookup.txt

I tried awk, fgrep commands but they are giving me different values; The expected output is:

  • 3
    Show us what you try. May 22, 2022 at 14:01
  • 1
    Should the match be limited to a specific field of the pipe-delimited file? Should it be case-insensitive, as implied by your example? May 22, 2022 at 14:34

2 Answers 2


Any reason why your grep approach didn't work?

grep -Fwif File.txt Lookup.txt

looks promising...?

  • 1
    It IS working with the sample data you posted.
    – RudiC
    May 23, 2022 at 7:59

Store the strings from File.txt as keys in an associative array in awk. For case-insensitive comparison, fold the keys to, e.g., lower-case.

When the second file, Lookup.txt, is being read, test whether the second field's lower-cased value is a key in the associative array. If it is, print the whole line.

awk -F '|' 'NR == FNR { key[tolower($0)]; next } (tolower($2) in key)' File.txt Lookup.txt

The variables NR and FNR hold the number of lines read overall and the number of lines read from the current file, respectively. If the values of these variables are the same, we're reading from the first file.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .