0

using a one line sed command , how could i get the something and someone value?

<value name="something">someone</value>

Using the following regex <value name="(.*)">(.*)<\/value> i could retrieve the values with success using the site https://www.regex101.com/. But i'm not sure how could i do it using the command line.

Thanks in advance.

thclpr
  • 5,437
  • 8
  • 47
  • 81
  • sure, i'll update the question =) – thclpr Dec 19 '14 at 11:24
  • you should specify a bit the possible content of something and someone (for special char `<>/"`) that can create perturbation in delimiter pattern or we can assume this is only word with eventually space – NeronLeVelu Dec 19 '14 at 12:05

3 Answers3

1

Something like

sed 's#.*name="\(.*\)">\(.*\)<.*#\1 \2#g'

Test

$ echo "<value name=\"something\">someone</value>" | sed 's#.*name="\(.*\)">\(.*\)<.*#\1 \2#g'
something someone
nu11p01n73R
  • 25,677
  • 2
  • 36
  • 50
0

Try this.

sed -r 's/.*"(.*)">(.*)<.*>$/\1 \2/'

Karthikeyan.R.S
  • 3,971
  • 1
  • 18
  • 31
0

Noting the usual caveats about parsing XML with regular expressions, here's an XML parsing tool in action on your sample data that finds the attribute value and tag value for a "value" tag with a "name" attribute.

xmlstarlet sel -t -v '//value[@name]/@name' -n -v '//value[@name]' -n file.xml
something
someone
Community
  • 1
  • 1
glenn jackman
  • 223,850
  • 36
  • 205
  • 328