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

(1/22) > >>


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.



--- 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}

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?

(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

EDIT: It's actually a For ... Next loop but same result.

For i = 0 to (number of items - 1) step 1
  blah blah blah

Also, the file I want to manipulate is 25GB! Is there a strategy to handle this?


[0] Message Index

[#] Next page

Go to full version