Trying to extract some strings from a file. Here's a simplified example of the text in the file:
<modelName>thing1</modelName><gtin>123456789</gtin><description>blah blah blah</description>
<modelName>thing2</modelName><gtin>789456123</gtin><description>blah blah blah</description>
<modelName>thing3</modelName><gtin>456789123</gtin><description>blah blah blah</description>
I want to extract just this part of each line: <gtin>xxxxxxx</gtin>
and put them into another file.
I do not want the whole line, just the gtin.
Here's what I tried:
Get-Content -Path C:\firstFile.xml -Readcount 1000 | foreach { $_ -match "<gtin1>*</gtin1>" } | out-file C:\gtins.txt
But as you can probably guess it's not working.
Any help is greatly appreciated. I have a feeling this is embarrassingly easy.
Thanks!