I am trying to print a regex pattern for the following piece of mail log. In particular I am trying to get the ID between the square brackets (see the second line for reference). Mar 29 03:48:13 mx-150 clamsmtpd: 14114F: accepted connection from: 127.0.0.1Mar 29 03:48:13 mx-150 postfix/smtpd[7445]: connect from unknown[127.0.0.1]Mar 29 03:48:13 mx-150 spamd[15674]: prefork: child states: IIand using the following command:awk '/\[\d+\]/ { print }' maillogAccording to https://regex101.com/r/pL7kN2/1 I am getting 1 match, however, awk is not returning anything. Why is that?
AWK print regex pattern
awk;regular expression
Try standard regexps (instead of perl regexps). This will print matching lines:awk '/\[[[:digit:]]+\]/ { print }' maillogTo extract and print the matching value inside the brackets:awk 'match($0,/\[[[:digit:]]+\]/) { print substr($0,RSTART+1,RLENGTH-2)}' maillog