简体   繁体   中英

Reprint a Dynamic RS (Record Separator) in awk

I am using following awk command to print only sections/Record that contain a specific text string (3705@192.168.1.5) in this example. This works very well but awk removes the record separator while printing out the output. For a generic text based RS, I can use {print RS, $0} to reprint it but in this scenario awk prints regular expression before each record.

awk 'BEGIN{ RS = "([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9].[0-9][0-9][0-9]" ;} /3705@192.168.1.5/ {print RS , $0}' /var/log/abc.log

Is there a way I can print the RS (Timestamp in this case) before each record? Thanks

You must already be using gawk since you are using multi-character RS so just print RT instead of RS . Read the book Effective Awk Programming, 4th Edition, by Arnold Robbins.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM