How to print the pattern match line using the awk command with which I need to print the next line with another pattern match

advertisements

My file is like this:

Setting application AAA active for user [[email protected]]
Connected from [::ffff:161.179.445.43]
Received client request: List database locks (from user [[email protected])
Connected from [::ffff:161.179.221.43]
Setting application AAA active for user [[email protected]]
Connected from [::ffff:161.179.445.43]
Setting application AAA active for user [[email protected]]
Connected from [::ffff:161.179.445.43]
Setting application AAA active for user [[email protected]]
Received client request: List database locks (from user [[email protected])
Setting application AAA active for user [[email protected]]
Setting application AAA active for user [[email protected]]

When search for setting application,it has to print setting application and if next line has ip address it has to print next line Connected from [::ffff:161.179.445.43] otherwise it has to print only setting application line.

my output is below:

Setting application AAA active for user [[email protected]]
Connected from [::ffff:161.179.445.43]
Setting application AAA active for user [[email protected]]
Connected from [::ffff:161.179.445.43]
Setting application AAA active for user [[email protected]]
Connected from [::ffff:161.179.445.43]
Setting application AAA active for user [[email protected]]
Setting application AAA active for user [[email protected]]
Setting application AAA active for user [[email protected]]

please help me how to write the unix code for this


awk '/Setting application/{print; k=1; next}; k && /Connected from/; {k=0}' input-file

or, slightly more elegant:

awk 'k && /Connected from/; k=/Setting application/' input-file