Let's say I have two files containing attribute names and properties, where different data is stored in two files:
1.txt:
abc12 3@ 50
edf13 4@ 50
dde8 3@ 50
2.txt
abc12 3@ 65
edf13 4@ 50
dde8 3@ 70
dde7 3@ 70
I want to grep as follows:
first- grep "3@" 1.txt | awk '{print $1}', then grep * 2.txt where star(*) represent output of first grep.
all should be done in a single line from the prompt.
expected output:
abc12 3@ 65
dde8 3@ 70
Thanks
With one awk process:
awk 'FNR==NR{if ($2 ~ "3@") a[$1]++; next} a[$1]' 1.txt 2.txt
the first condition{action} means when reading from first file, increase the array element with this first field as hash. The second condition a[$1] is true when this element is one or more, this is checked for the second file and the default action is to print the line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With