awk searching strings from file

6,886

Why search fields one-by-one? Why not search whole lines at a time?

grep -f find.txt path_to_100_files/*
Share:
6,886
Jeff Schaller
Author by

Jeff Schaller

Unix Systems administrator http://www.catb.org/esr/faqs/smart-questions.html http://unix.stackexchange.com/help/how-to-ask http://sscce.org/ http://stackoverflow.com/help/mcve

Updated on September 18, 2022

Comments

  • Jeff Schaller
    Jeff Schaller almost 2 years

    I'm currently using

     $ awk 'NR==FNR{a[$1];next} ($3 in a)' find.txt path_to_100_files/*
    

    which uses find.txt strings to search multiple files within path_to_100_files/ for matches.

    find.txt contains

    [email protected]
    [email protected]
    

    and then path_to_100_files/ contains files such as

    0.0.0.0:002921931:[email protected]
    123.0.0.1:00029382:[email protected]
    

    now what this is doing is only searching the 3rd column for the strings from find.txt, but i need it to search the entire file/every column?

    as some files may be 5 columns long, or 9 columns long example,

    0.0.0.0:002921931:1111111:[email protected]
    123.0.0.1:00029382:1111111:11111:[email protected]
    

    I've tried to change ($3 in a) to like ($0-$9 in a) but doesn't seem to work?

  • Wildcard
    Wildcard over 6 years
    You should add a -F as well for fixed-string search.
  • done
    done over 6 years
    @Wildcard As well as add a -o to only output matches.