2

I have File which contains Records

qwe.google.com IN A 1.1.1.1
qwe.google.com   IN {uneven-space} A{space}1.1.1.1
qwe.google.com  IN     CNAME      asd.google.com

I need to grep all the lines which contains IN A, as it contains uneven spaces in between i am not able to do so.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
  • Can IN A appear anywhere except exactly where you want to match on if? For example could a string containing IN A like TIN APPLES appear in your input? – Ed Morton Jun 11 '20 at 03:12

3 Answers3

5

You can use

grep -E "IN[[:blank:]]+A" file
  • [[:blank:]] matches spaces and tabs, similar to [ \t]
binarysta
  • 3,032
2

You can use

grep -E "IN +A" file

which will match (via extended regular expressions) one or more whitespaces between IN and A.

If there can be other forms of whitespace (namely tabs) in between IN and A, you may need to use a character list or character class instead of the simple space, see this answer for example.

AdminBee
  • 22,803
1
awk '$2 == "IN" && $3 == "A"'

May be closer to what you want (look for internet A records in that output).

With grep:

grep -E '[[:blank:]]IN[[:blank:]]+A[[:blank:]]'

would be better than just

grep -E 'IN[[:blank:]]+A'

Which could match on a line like:

example.com   IN      TXT     "v=spf1 include:EXAMPLE.IN ALL"

for instance.

In any case, both grep commands would match on:

example.com   IN      TXT     "blah IN A bleh"