Text manipulation in PowerShell

excelos

Well-known Member
Joined
Sep 25, 2011
Messages
592
Office Version
  1. 365
Platform
  1. Windows
Hello

I am looking for a free and fast way to manipulate large amounts of data (GigaBytes).

I think Powershell is the most appropriate as it comes with Windows and it is fast. Do you have any other alternatives?

As for Powershell, can you help me please with a script that will read the lines of a document and for each line, it will delete the text outside a specific regex?

I am not sure how to structure such script, which commands to use etc.

Thanks!
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Notwithstanding you had no takers for your question or follow-up (but at the time of posting have had 575 views[!]), this may be far too late...

This script, as an example, will ignore any line that does not have "Powershell" appearing in it (-like "*Powershell*") from all files with the extension .txt in the directory where the script is residing, naming the output files with the extension .out.txt
Code:
$files = Get-ChildItem -Path $PSScriptRoot -Recurse -Include *.txt
foreach ($file in $files){
    $outfile = $file.DirectoryName + "\" + $file.BaseName + ".out.txt"
    $strREGEX = "*Powershell*"
    $strOutput = ""
    foreach($Line in Get-Content $file) {
        If ($Line -like $strREGEX) {
            $strOutput = $strOutput + $Line + [environment]::NewLine
        }
    }
    $strOutput | Out-File -FilePath $outfile
}
Is that the sort of thing that you are/were after?
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top