How to grep the lines between the parent tags [duplicate]

 <login-config> <auth-method>DIGEST</auth-method> <realm-name>UserDatabase</realm-name> </login-config>

I need to grep the lines between <login-config> and </login-config>, can anyone suggest the best method

3

1 Answer

Command

sed -n '/\<login-config/,/\/login-config/{//!p;}' file

will print the desired output, even for multiple matches of the opening/closing pattern.

Command

awk '/\<login-config/{f=1;next} /\/login-config/{f=0} f' file

works but only if there is only one match (it could surely be fixed).

You Might Also Like