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

<< < (19/22) > >>

Thanks, but it needs me to run it as admin, which I cannot.-kalos (August 21, 2018, 09:42 AM)
--- End quote ---

And it's taken 4 pages to find that out - something that should have been stated earlier.

Any idea why the below does not work?

(gc *.xml) -match '(?s)<\?xml\ version="1\.0"\ encoding="UTF-8"\?>.+?</dbts:PmryObj>'
--- End quote ---


Q: Whats's the input data?
A: We don't know.

Q: What's the command output?
A: We don't know.

Q: What version of Powershell are you using?
A: We don't know.

Q: What OS are you using, (including architecture)?
A: We don't know.

Q: What's the statistics of the input file, (eg. size)?
A: We don't know.

Q: Why the hell are you trying to process all files at once instead of one at a time?
A: We don't know.

etc, etc, etc, etc ... for 4 pages.

Idea: We don't know.
Why: See point 1 here.
-4wd (August 22, 2018, 06:30 AM)
--- End quote ---

Did you look up how to get the answers on Google for the ones related to your environment?  And several of those that you're giving are not things that you wouldn't know.  You know what your input data is.  You know what you would expect as an output.  You know this stuff or can get it.  Which leads people to believe that you're not trying to give us the information.  And so why waste time with incomplete information?  Learning difficulties is just an excuse for all of the questions that you posted.  None of those have to do with learning.

I literally highlighted what you typed for "What version of Powershell are you using" right clicked on it, searched in Bing, and came up with the answer.  There's no reason you couldn't do the same.


--- Code: PowerShell ---Clear-Host$products = (Get-Content "test.xml" -Raw) -xxxxx '(....)^.*?(..........................)'for ($i = 1; $i -lt $products.Count; $i += 2) {  $products[$i] -xxxxx '(.........)(...)(...)' | Foreach { Write-Host ($Matches[0] + (((($products[$i] -replace '(<[^>]+>|\s)', '; ' ) -replace '`r', '') -replace '`n', '') -replace '(;\s)(;\s)+', '$1').TrimEnd('; ')) }}
Outputprod1; PRD; PRD_XE; 10004; 2018-07-23; REPAIRS; REP_XE; ED
prod2; PRD2; PRD_XE2; 10005; 2018-12-23; REPAIRS2; REP_XE2; ED2
prod3; PRD3; PRD_XE3; 10014; 2013-07-23; REPAIRS3; REP_XE3; ED3
prod4; PRD4; PRD_XE4; 10567; 2010-07-23; REPAIRS4; REP_XE4; ED4
prod5; PRD5; PRD_XE5; 10004890; 2015-05-15; REPAIRS5; REP_XE5; ED5

-xxxxx = An operator

'(....)^.*?(..........................)' = A RegEx, number of dots represents number of characters in it.

'(.........)(...)(...)' = A RegEx, number of dots represents number of characters in it.

Mental exercise complete ...

Single Line Version
--- Code: PowerShell ---gci *.xml | % {(gc $_ -Raw) -xxxxx '(....)^.*?(............................)' | % { if ($_ -xxxxx '(.........)(...)(...)') { ($matches[0] + (((($_ -replace '(<[^>]+>|\s)', '; ' ) -replace '`r', '') -replace '`n', '') -replace '(;\s)(;\s)+', '$1').TrimEnd('; ')) } }}

Maybe we should just shut this down as it's getting a bit heated, and I think that everyone is done.
-wraith808 (August 23, 2018, 11:46 AM)
--- End quote ---
Agree. Moderator, please move this thread to underground.-anandcoral (August 24, 2018, 06:49 AM)
--- End quote ---

Nah, just remove posts 94-97, 100-104 and then lock the thread - there is useful information in the various posts which won't be seen if moved to the Underground.

Cleaned up the thread as requested.

Thanks Wraith.

Regarding the script above:

* There's enough information within it to discern what the two missing operators are.
* The first RegEx has been given within this thread.
* The second RegEx will require a little lateral thinking, searching, and experimentation - just like the third did.


[0] Message Index

[#] Next page

[*] Previous page

Go to full version