The regular expressions (at least they way you are using them) should be constants. Also, the use of the asterisk means you want to match zero or more of the preceding token (which happens to be a 1). This is most likely not what you had in mind. Additionally, the
match() function is a GNU extension used for some more powerful constructs such as placing matches in an array. There is no reason to use it for something so simple as an “if” statement.
Anyway, here is the “corrected” version using
gawk’s
match():
Code:
awk '{if(match($0,/PATTERN1.*PATTERN2/))print $0}' file
And here is a much more elegant version (and a style you will most likely continue to see):
Code:
awk '/PATTERN1.*PATTERN2/{print $0}' file