$fileName = "C:\Folder1\file.txt" $newfilename = "C:\Folder1\newfile.txt" # Get content of file $content = Get-Content -Path $fileName -Raw -Encoding UTF8 $words = (((($content.Split(" ")).Replace(".","")).Replace(",","")).Replace("`n","")) #Define function Function Create-Words { $script:word1 = Get-Random -InputObject $words # get first random word from word list $script:word2 = Get-Random -InputObject $words # get second random word from word list Write-Host "First word: " $script:word1 -ForegroundColor Green # write output word1 Write-Host "Second word: " $script:word2 -ForegroundColor Magenta # write output of word2 } # Execute function Create-Words # Replace random word1 with random word2 and write file $content.Replace("$word1", "$word2") | Out-File -FilePath "$newfilename" -force
The rain in Spain falls mainly in the plain.
The racustard custard Spacustard falls macustardly custard the placustard.
<pre> ((Get-Content -Path C:\Folder1\file.txt -Raw ) -split "\s+" | Sort-Object {Get-Random} ) -join ' ' | Out-File -FilePath C:\Folder1\NewFile.txt
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)