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

<< < (11/22) > >>

kalos:
Last, how to find the next regex match in the file?
--- End quote ---
Add another Select-String line with the next RegEx.
-4wd (August 06, 2018, 04:41 PM)
--- End quote ---

No, I don't mean a different regex. I mean the same regex. The same regex may have multiple matches in one file. How do I make the script to find the first instance, do stuff, then find the second instance, do stuff etc?

Also, how do I make . to include newline?

Also, what is | % { $_.Matches } | % { $_.Value } >> $outfile exactly?
I don't know what % and { $_. and Value are?

Also, how do I return a specific part from regex? In normal regex text editors, you put the part in parentheses and then you replace them with \1 etc. How do I do it in Powershell?

Also, I should be able to figure this out myself, but I am looking for a neat code and I can only manage to come up with messy stuff: is there a script to delete lines not containing specific literate phrases? E.g. not containing 'lue } >> $ou' without having to go through each character to check if it needs escaping or not.

Ath:
You obviously don't understand what we wrote earlier. I already gave 2 (two) possible ways how to handle that. And there are other solutions too.

Like 4wd, I'll pick up again after you start giving complete examples of real pieces of a data file with exact descriptions of what you want to achieve, not of descriptions of how you think it should be handled/solved.

kalos:
I want answers to specific questions, not a complete solution. It is not possible for anyone external to offer a complete solution because the source data cannot be shared.
Also, most of my questions are for my own understanding and may not directly relate to the specific problem.

Ath:
most of my questions are for my own understanding and may not directly relate to the specific problem.
-kalos (August 07, 2018, 09:01 AM)
--- End quote ---
You obviously don't understand what we wrote earlier. I already gave 2 (two) possible ways how to handle that. And there are other solutions too.
-Ath (August 07, 2018, 08:50 AM)
--- End quote ---
To spell it out, again:

* Use a programming or script language
* Use sed
* And a third solution to add to the confusion: Use awkw

4wd:
It is not possible for anyone external to offer a complete solution because the source data cannot be shared.-kalos (August 07, 2018, 09:01 AM)
--- End quote ---

And there you go, a perfect illustration of the main problem.

Despite asking for raw data several times starting from page 1, (and getting various snippets and interpretations), we find out on page 3 that the data can't be shared.

Any reason why you couldn't have told us this when it was first asked?

Also, what is | % { $_.Matches } | % { $_.Value } >> $outfile exactly?-kalos (August 07, 2018, 04:16 AM)
--- End quote ---

|
--- End quote ---
A Pipe

%
--- End quote ---
ForEach-Object

$_
--- End quote ---
Object passed through pipe.

Matches
--- End quote ---
A Property of the object.

Value
--- End quote ---
A Property of the object.

You do know that they have this thing called Google, right?

Let's say I want to extract the numbers in the fields ui_mode etc or each of these three separate records.-kalos (August 05, 2018, 01:55 PM)
--- End quote ---


--- Code: PowerShell ---gci *.txt | % { sls $_.Name -Pattern '^.*"ui_mode",(\d+).*$' -a | % { $_.Matches } | % { $_.Groups[1].Value } >> K:\out.txt }

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version