I'm trying to grep/sed from the following xml data:

address="11.800.96.10" name="_ldap._tcp.gc._msdcs.example.com" port="3268" target="aws-sit2.example.com" type="SRV"/>

I wanted to retrieve below information in below format:

address value, name value, port value

Each record will have a carriage return after one liner recorded values extracted. How do I achieve this?

  • How have you attempted to solve this problem on your own? Please include any relevant commands in your question.
    – oxr463
    Jul 3, 2019 at 12:10

2 Answers 2


For parsing XML, use an xml parser, e.g. xmlstarlet!

xmlstarlet sel -t -m '//record' \
  -v '@address' -o " " \
  -v '@name' -o " " \
  -v '@port' -n \

Change the separator after -o to your needs. Or use -n for newline.

  • This doesn't make use of either sed, nor grep.
    – oxr463
    Jul 3, 2019 at 12:10
  • 1
    Using sed and/or grep is a really bad idea for parsing xml data.
    – pLumo
    Jul 3, 2019 at 12:16
  • In general I would agree, and maybe you should include this in your answer; but no mention is made of how this will be utilized.
    – oxr463
    Jul 3, 2019 at 12:21

awk '{print $1", "$2", "$3}' | sed -e 's/[=]/ /g' -e 's/["]//g'
This should work fine

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.