Extract WORD between two constant strings

I have the following string

xml_srx_name="<name>SRX-NAME</name>"

I am trying to print the text between > and <
so it would print SRX-NAME

I am really close but this is what I get: >SRX-NAME< which is what I was able to achieve with this command:

$ cat $xml_srx_name | awk '/SRX-NAME/ {print $1}' | grep -oPz "(?s)>.*?<" | tr '\0' '\n'

Output:
>SRX-NAME<

>Solution :

You can try

  1. Add | tr -d '<>' in the end
  2. Use cat … |grep -o SRX-NAME
  3. Use cat … |cut -d \> -f 2 | cut -d \< -f 1

Leave a Reply