I've got a series of patterns stored in foo.txt and I want to iterate over those patterns and see which match lines in file bar.txt.
while read PWW
do
cat user/dump/bar.txt | awk '/${PWW}/{print $2}' >> user/dump/out.txt
done < user/dump/foo.txt
foo.txt:
2100001b32
2100001b38
3100001b35
4100001b28
5100001b46
6100001b56
bar.txt:
2100001b32 good
2100001b38 bad
3100001b35 okay
4100001b28 large
5100001b46 good
6100001b56 bad
desired out.txt:
good
bad
okay
large
good
bad
I am unable to search for the values in foo.txt. The while loop runs and gives me empty output. I guess awk is looking for ${PWW} (literally) instead of its values from foo.txt.
How can I make it work?
My environment is Solaris 5.10, using Korn shell, with basic awk
(old awk).
cats, avoid loops in shells if possible, don't repeatedly call (awk-) processes in loops unnecessarily.) - Instead use anawk-only approach, like the suggested "pureawk" answer below. -awkcan accept a file list (as many other commands also do), it does implicit (fast) looping, and the resulting code is much simpler.awkaccepts lists of files as arguments, not only "single file". - As said; the way you wrote your sample (with all its deficiencies) is a strong indication that you may not know what's possible or sensible. - It would be helpful if you just tell us exactly "what you wanted"; we could certainly make good suggestions. - Anyway; your choice.grep -f foo.txt. If there are additional constraints, edit the question accordingly.