sarge
sarge

Reputation: 25

Trying to parse a DNS zone file with awk and am having an issue matching leading characters with awk

I'm trying to parse a text file with an awk one liner and:

  1. Delete the first line (header)
  2. Delete all lines that begin with '(' (open paren)
  3. Drop the 4th column

Example data:

Name    Type    Data    Timestamp
(same as parent folder) Start of Authority (SOA)    [69671], server1.abc.com., hostmaster.abc.com.  static
(same as parent folder) Name Server (NS)    server2.abc.com.    static
access  Host (A)    192.168.99.190  static
apps    Host (A)    192.168.99.181  static

I'm able to do 1 & 3, but my regex must be off for the '(' match:

awk -F$'\t' 'NR > 1' | awk '!/^(/' '{print toupper($1),$2,$3}' test.txt > out.txt

awk: cmd. line:1: error: Unmatched ( or (: /^(/

I tried escaping the open parenthesis but that didn't work either. I started pipelining the second awk because I thought the NR filter was getting in the way, but it's obvious I'm missing something (probably basic).

Upvotes: 0

Views: 353

Answers (1)

Ed Morton
Ed Morton

Reputation: 204638

$ awk 'BEGIN{FS=OFS="\t"} NR>1 && !/^\(/{print toupper($1), $2, $3}' file
ACCESS  Host (A)        192.168.99.190
APPS    Host (A)        192.168.99.181

Upvotes: 1

Related Questions