ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > General Software Discussion

Extract REGEX matches from multiple text files

<< < (9/22) > >>

kalos:
By the way, this script looks amazing (From: https://www.codeproject.com/articles/61900/powershell-and-xml):

PS C:\> $xml = (Get-Content file.xml)
PS C:\> $xml = [xml](Get-Content file.xml)
PS C:\> $xml.SelectNodes("/employees/employee")

id                                      name                                    age
--                                      ----                                    ---
101                                     Frankie Johnny                          36
102                                     Elvis Presley                           79
301                                     Ella Fitzgerald                         102

But I cannot make it work for my file. Any hint?

kalos:
Guys, the more I am looking on it, the more I am convinced that Regex would be the best solution.

Can anyone tell me please how to find a regex in a file and append it to a file? Also, how to loop that? Last, how to find the next regex match in the file?

4wd:
But I cannot make it work for my file. Any hint?
-kalos (August 06, 2018, 10:55 AM)
--- End quote ---

Yeah, as Ath suggested, your XML  contains CDATA so you have to read that separately.

https://stackoverflow.com/questions/1274070/how-to-read-cdata-in-xml-file-with-powershell

kalos:
But I cannot make it work for my file. Any hint?
-kalos (August 06, 2018, 10:55 AM)
--- End quote ---

Yeah, as Ath suggested, your XML  contains CDATA so you have to read that separately.

https://stackoverflow.com/questions/1274070/how-to-read-cdata-in-xml-file-with-powershell
-4wd (August 06, 2018, 11:37 AM)
--- End quote ---

I will try but can you help me with the below:

Guys, the more I am looking on it, the more I am convinced that Regex would be the best solution.

Can anyone tell me please how to find a regex in a file and append it to a file? Also, how to loop that? Last, how to find the next regex match in the file?


-kalos (August 06, 2018, 11:36 AM)
--- End quote ---

Ath:
If I could convert the XML file in a flat structured file
-kalos (August 06, 2018, 08:13 AM)
--- End quote ---
Converting your .xml to .csv is a quite easy one-liner in Powershell, assuming a single xml file, into a single .csv file:

--- Code: PowerShell ---$([xml]$(Get-Content .\kalos-data1.xml)).SelectNodes("/CATALOG/PLANT")|Export-Csv .\kalos-data1.csvThe reason it wasn't working for you was probably that you didn't account for xml to be case-sensitive.

Parsing an .xml file containing CDATA tags with a regex is close to impossible to get right, as nearly any content is possible inside such CDATA tag, including valid xml...

Guys, the more I am looking on it, the more I am convinced that Regex would be the best solution.
-kalos (August 06, 2018, 11:36 AM)
--- End quote ---
Please listen to people with more (programming) experience than you have, you are really trying to hammer round screws into square holes here, don't do that, you'll hurt yourself.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version