Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Powershell Split file at a word

$
0
0

Hello


I am trying to split a file

Everytime it finds the Word SPLIT

The below did not work



$Path = "C:\Users\PLW\Desktop\a\"


$InputFile = (Join-Path $Path "File.txt")

$Reader = New-Object System.IO.StreamReader($InputFile)

While (($Line = $Reader.ReadLine()) -ne $null) {
    If ($Line -match "SPLIT") {
        $OutputFile = $matches[1] + ".txt"
    }

    Add-Content (Join-Path $Path $OutputFile) $Line
}

http://superuser.com/questions/466363/how-to-split-a-text-file-into-multiple-text-files

I don't know what the problem is :(

thank you for your help


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>