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

<< < (13/22) > >>

kalos:
Any idea why this does not work?
Get-Content *.xml | Out-String-kalos (August 09, 2018, 10:53 AM)
--- End quote ---

I have a better idea, you tell us why you think it doesn't work.

gc *.xml -match *regex*
does not work :(
--- End quote ---


--- Code: PowerShell ---Get-Help Get-Content
You tell us why it doesn't work.
-4wd (August 09, 2018, 07:59 PM)
--- End quote ---

Mmm I don't know why Get-Content *.xml | Out-String does not work to be honest.
I read at https://ss64.com/ps/out-string.html:
Send the content of Test1.txt to the console as a single string:
PS C:\> get-content C:\docs\test1.txt | out-string
So, shouldn't it work?

As for gc *.xml -match *regex* it seems that -match does not go after gc, but how do I connect/pipe these?
I had no clue, but I found in an irrelevant place on the internet this:
(Get-Content .\input.txt) -join "`r`n"
How should I know that I need to parenthesise the first object? Where does it say that in PS manual?

wraith808:
I think he was asking, what do you mean doesn't work?  You just said it didn't work and didn't give any indication of what happened.

4wd:
They were to get a couple of points across, which were completely missed.

1. His guess as to why the first doesn't work will always be better than whatever we could come up with because we never, ever get enough information/context to make an informed guess/opinion.

2. He doesn't read what has already been given because the answer is in this thread.

PS. Sorry mouser ...  :-\

kalos:
2. He doesn't read what has already been given because the answer is in this thread.

PS. Sorry mouser ...  :-\
-4wd (August 10, 2018, 08:38 AM)
--- End quote ---

Oh sorry but due to my learning difficulty I need to be pinpointed to the exact thing.
I am developing my PS understanding though and it seems very powerful  :Thmbsup:

I wrote this script:
(gc *.txt)  -replace "regex1(.+?)", "`$1" >> out

It replaces the regex with the reference from the regex and outputs to a new file. Not exactly what I want it to do.
I want to output the reference, any idea how to do that?
Also, I want to run sequential several regex matches with their own references, one by one and append each result to the output file.

I believe piping commands does not achieve this. I think piping is about getting the output object from the previous command and feed it to the next command. However, I want the various regex matches to work on the original object sequentially. This is a bit tricky, any idea?


Also, can you tell me please how to find and select and append values from multiple xml nodes knowing their XPath?
I do that and it doesn't work:
Select-Xml -Path "*.xml" -XPath "/html:book/html:Entity" >> out
Also this doesn't work:
PS H:\> [xml]$Types = get-content *.xml
PS H:\> select-xml -xml $Types -xpath "//html:Entity"
select-xml : Namespace Manager or XsltContext needed. This query

Thanks!

Ath:
Also, I want to run sequential several regex matches with their own references, one by one and append each result to the output file.
-kalos (August 10, 2018, 09:43 AM)
--- End quote ---
You have to make clear whether the results from the separate queries have any positional relation to each other, or can the queries be run one after the other and the output of the second, third, etc., runs appended to the first regex run?

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version