Sorry but I have never asked a question on a board such as this, please excuse inexperience.
I am trying to take a field from an input file, say field two from abc.txt, and match it in the def.txt. The problem is I also need to match an additional pattern in the def.txt file.
For exapmle, field 2 in abc.txt is "3". And the pattern I want to search for in def.txt is "efg". I need it to return all lines that match pattern "efg" and that contain "3".
As an additional constraint I want it to stop searching after it reaches a certain value, say "END". I have exhausted my efforts to find a simple one liner for this in awk or any variant.
I am befuddled on all of these points, is it ok to ask for help on this as a novice? Any assistance is appreciated, thanks.
Here is the code, which is not working at all:
awk 'BEGIN { FS = " " } ;NR==FNR{a[$2]=++i;next} '{if ( $5 in a) && ($0 ~ '/efg/')} {print $0}' abc.txt def.txt
I am trying to achieve 3 things:
Match input file field to def.txt fields
Match a pattern in def.txt
Stop the search when a value is encountered, for example "END".
Hoping for a one line solution if possible, I am just too much of an AWK beginner.
Sample Input
Abc.txt
1
2
3
4
Def.txt
1 abc
1 efg
1 efg some more data
END
2 ghi
2 efg
2 efg some more data
END
3 jkl
3 efg
3 efg some more data
END
and so on...
Expected Output
1 efg
1 efg some more data
2 efg
2 efg some more data
3 efg
3 efg some more data
and with any help to have it stop upon reaching "END." Instead of going through the entire file and printing the subsequent instances of 1 efg, 2 efg, etc.
'/efg'/? In any case, post some sample input and expected output.