0

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

123@hotmail.com
1235@hotmail.com

and then path_to_100_files/ contains files such as

0.0.0.0:002921931:123@hotmail.com
123.0.0.1:00029382:1235@hotmail.com

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:123@hotmail.com
123.0.0.1:00029382:1111111:11111:1235@hotmail.com

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

1

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

grep -f find.txt path_to_100_files/*
2
  • You should add a -F as well for fixed-string search.
    – Wildcard
    Jan 6 '18 at 1:04
  • @Wildcard As well as add a -o to only output matches.
    – ImHere
    Jan 6 '18 at 2:42
0

If the email is the last field in the 100 files, use:

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

If you must look into each field, you need a loop:

awk -F: 'NR==FNR{a[$1];next} {for (i=1;i<=NF;i++) {if ($i in a) {print;break}}} find.txt path_to_100_files/*

But the simpler call is using grep:

grep -oFf find.txt path_to_100_files/*
0

First find the maximum column exsists in the files using below command and take the maximum value from it

k=`awk -F ":" '{print NF}'  path_to_100_files/*  | sort -nr | head -1`

Used for loop to get it checked with every column

for ((i=0;i<=$k;i++)); do awk -v i="$i" -F ":" 'NR==FNR {a[$1];next}($i in a) {print }’   find.txt path_to_100_files/*   ; done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.