Score:-1

How to grep the lines between the parent tags

jp flag
  <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

muru avatar
us flag
This looks like XML. Is it supposed to be XML?
CrazyTux avatar
us flag
Does this answer your question? [How to extract a string from a json file and put into a variable (Linux)](https://askubuntu.com/questions/1357926/how-to-extract-a-string-from-a-json-file-and-put-into-a-variable-linux)
bac0n avatar
cn flag
`xmllint --xpath '//login-config/*' file.xml`
Score:0
gh flag

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).

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.