help on awk contain between two columns
file.txt
AD615 13J04084706 53H04094706 0-000-0000 HUWSAFRA-615-J:1-0-13-53 ANOZM 15A01011902 01H01011902 0-000-0000 HUWM219-00-209_ANOZM:1-0-15-1 MDM1G 09A01010812 27H01010812 0-000-0000 HUWM301-00-411_MDM1G:1-0-9-27 ABAH9 15A07010408 06S02010308 0-000-0000 MRGDNBKAA_ABAH9-A:1-1-15-6 AD417 08H11114504 20Z06044504 0-000-0000 IP417SULT-H:1-1-6-20 AD106 05P02123801 09Z02133801 0-000-0000 IP106ULYA-P:1-1-3-9 output should be ANOZM 15A01011902 01H01011902 0-000-0000 HUWM219-00-209_ANOZM:1-0-15-1 MDM1G 09A01010812 27H01010812 0-000-0000 HUWM301-00-411_MDM1G:1-0-9-27 ABAH9 15A07010408 06S02010308 0-000-0000 MRGDNBKAA_ABAH9-A:1-1-15-6 take $1 as main data then serach contain on $5 $1 have ANOZM MDM1G ABAH9 already contain on $5 HUWM219-00-209_ANOZM:1-0-15-1 HUWM301-00-411_MDM1G:1-0-9-27 MRGDNBKAA_ABAH9-A:1-1-15-6 awk '$1~/$5/ {print $0}' file.txt but it does not show me what i need ? anybody can help me |
Try this ...
Code:
awk '$5~$1' $InFile >$OutFile |
Thanks Daniel
|
another question in same think
if I have two files need to make comparison between them based on contain text how i can do such as this file 1 13J04084706 53H04094706 0-000-0000 HUWSAFRA-615-J:1-0-13-53 15A01011902 01H01011902 0-000-0000 HUWM219-00-209_ANOZM:1-0-15-1 09A01010812 27H01010812 0-000-0000 HUWM301-00-411_MDM1G:1-0-9-27 15A07010408 06S02010308 0-000-0000 MRGDNBKAA_ABAH9-A:1-1-15-6 08H11114504 20Z06044504 0-000-0000 IP417SULT-H:1-1-6-20 05P02123801 09Z02133801 0-000-0000 IP106ULYA-P:1-1-3-9 file 2 ANOZM MDM1G ABAH9 output should be like this ANOZM 15A01011902 01H01011902 0-000-0000 HUWM219-00-209_ANOZM:1-0-15-1 MDM1G 09A01010812 27H01010812 0-000-0000 HUWM301-00-411_MDM1G:1-0-9-27 ABAH9 15A07010408 06S02010308 0-000-0000 MRGDNBKAA_ABAH9-A:1-1-15-6 |
Have a look at this:
Code:
#!/bin/bash Code:
./awk.phpshell.sh |
Quote:
Code:
grep -Ff $InFile2 $InFile1 >$OutFile |
Quote:
thanks for your help ... but this very difficult to trace the code for me .any other way Dear Daniel i try grep -f but it show me these messages grep: Memory exhausted grep: memory exhausted: Cannot allocate memory |
Quote:
Code:
awk ' Once file2 is processed awk will start reading file1, one line at the time. Each line from file1 is checked against the array entries, if it matches it prints both the content of the array and the line from file1 Quote:
But I'm only testing with the examples given by you. Looking at the error you posted I can only assume that your real files are much bigger and may cause a memory problem. But that's an assumption on my side, we won't know for sure until you give some extra info. |
Quote:
Daniel B. Martin |
You can even make the 'if' a little simpler if you check against the index:
Code:
awk 'FNR==NR{_[$0];next}{for(i in _)if($NF ~ i)print i,$0}' file2 file1 |
I am really appreciated your support all of you guys
Marked this thread as solved :) |
All times are GMT -5. The time now is 03:12 PM. |