Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

$ 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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading