Hello I have 2 files with the first file containing a few values for example
powershell
vectormaps
JuniperSA
and the second file containing values and and ID
appid uid
SplunkforSnort 340
powershell 610
vectormaps 729
JuniperSA 826
postfix 933
SplunkforJuniperSRX 929
TA-barracuda_webfilter 952
TA-dragon-ips 954
dhcpd 392
So im trying to run a while loop with AWK to get the values and their corresponding ID's but the output file seems to be writing something else. This is how im trying to run the while loop.
while read $line;
do
awk '/'$line'/ {print $0}' file2.csv > new
done < file1
My expected output should be
powershell 610
vectormaps 729
JuniperSA 826
but my output is
appid uid
SplunkforSnort 340
powershell 610
vectormaps 729
JuniperSA 826
postfix 933
SplunkforJuniperSRX 929
TA-barracuda_webfilter 952
TA-dragon-ips 954
dhcpd 392
it seems as if nothing is happening. What am i missing here?
awk
mandatory ? what's wrong withgrep -f pattern list
? – Archemar Jul 27 '22 at 11:24grep -f pattern list
, for example, would falsely match substrings and strings containing regexp metachars and strings in the wrong column and there aren't options to grep to let you modify the call to grep to say "only match a literal string in the first column". – Ed Morton Jul 27 '22 at 12:05awk 'NR==FNR{a[$1]=$2;next}; $1 in a' file1 file2
should work. The command is taken from this and this. – Prabhjot Singh Jul 27 '22 at 16:55join
here. That’s what it is built for. – D. Ben Knoble Jul 27 '22 at 21:51