Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • 2
    Do a string comparison instead of a pattern match: $4 == pattern, although it would possibly be quicker with a single join command (no looping). Commented Sep 18, 2019 at 21:05
  • 2
    or $4 ~ "^"pattern"$" if pattern is actually a regexp and not a fixed string. i.e. normal awk string concatenation. so $4 ~ "^" pattern "$" works just as well and is, perhaps, slightly more readable. Commented Sep 19, 2019 at 5:02
  • 1
    GNU Awk 4.2.1 on Debian 10: '$1 ~ "pattern" {print $0}' seems to do an exact match (in this case a different var, $1). I would be careful though given the difference between AWK versions and flavours. Commented Mar 27, 2023 at 12:49