I have file with the content of
123
234
345
I am using a foreach loop to read each line of the file.
I have a requirement like: I would like to remove each line of the file inside the foreach loop.
Is there anyway to remove line of the file inside foreach loop?
Here's what I've tried:
$source1 = "Y:\New Documents\test.txt"
foreach ($line in Get-Content $source1) {
$find = $line
(Get-Content $source1).replace($find,"") |
Set-Content $source1
}
I am able to clear the content of file and I don't know how to make file with zero size.
Clear-Content $file?