2

I used the sed function to exact the values from a XML file but I'm stuck on how to assign it to a array.

This is the sed code

sed -n 's|<url>\(.*\)</url>|\1|p' filename.xml

The result is

VALUE1
VALUE2
VALUE3
VALUE4

How to assign these values to an array?

Thank you

1
  • 1
    Not an answer, but somewhat related - you might get some use out of xmlstar.sourceforge.net, makes shell scripting with XML a little more reliable. Commented Feb 27, 2014 at 6:49

1 Answer 1

6

Put the values inside (...) in an assignment:

IFS=$'\n' array=($(sed -n 's|<url>\(.*\)</url>|\1|p' filename.xml))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.