Main Area and Open Discussion > General Software Discussion
Extract REGEX matches from multiple text files
kalos:
Hello!
Which tool/scripting language can I use to match REGEX strings and extract them to a new file or to just delete the non matching strings from multiple text files?
It would help to be easy to write as I cannot learn complicated syntax!
Also, ideally it should work via command line as I am talking about many many files which can be huge.
Thanks!
4wd:
--- Code: PowerShell ---$outfile = 'K:\output.txt'$regex = '^Function.+'$items = Get-ChildItem -Path *.ps1 # *.txt , *.foo , *.whateverfor ($i = 0; $i -lt $items.Count; $i++) { Select-String -Path $items[$i] -Pattern $regex -AllMatches | % { $_.Matches } | % { $_.Value } >> $outfile}
kalos:
Thanks but I am not familiar with this language.
I think Autohotkey would be more appropriate for me as it has simple structure (what are the $i = 0; $i -lt $items.Count; $i++ they look like Aramaic to me :P)
Can you tell me the commands/structure in AHK to do this:
search for a regex1, extract regex2 from regex1 (ie append to a new file), and continuously loop until there is no other regex1 found
Also, how do I specify an exact string in regex? I want to specify the string <dsf:tsdfgd trsdfge="urn:x-ssdfgs-dfg-com:isdfgc/tg4r3e-i4d" id="OsdfgsdfD">
and I don't want to escape every single symbol etc.
Is there a way to search for an exact string literally?
4wd:
(what are the $i = 0; $i -lt $items.Count; $i++ -kalos (August 03, 2018, 07:04 AM)
--- End quote ---
While i < (number of items)
blah blah blah
i = i + 1
Wend
EDIT: It's actually a For ... Next loop but same result.
For i = 0 to (number of items - 1) step 1
blah blah blah
Next
kalos:
Also, the file I want to manipulate is 25GB! Is there a strategy to handle this?
Navigation
[0] Message Index
[#] Next page
Go to full version