I am able trim all the contents in file
$lines=(Get-Content $BaselineFile)
foreach ($line in $lines) { $line= $line.Trim() }
But how to put back the result in same file. ($Baselinefile)
Using PowerShell newline in Command To add newline in the PowerShell script command, use the` (backtick) character at the end of each line to break the command into multiple lines.
^0+ matches one or more ( + ) zeros at the start ( ^ ) of the string and replaces them with a single zero. Positive look-ahead assertion (? =[^.]) effectively removes all leading zeros ( ^0+ ) as long as such a zero isn't followed by a literal .
In PowerShell, using Get-Content to skip first line of file, use Skip parameter with value to skip line. It will skip those number of lines and display rest of the lines of file.
Powershell Write Output to File. There are a couple of ways to write the output of PowerShell to a file. The most common ways are to use the Out-File cmdlet or the redirection operator > . Other options are to use the Set-Content and Add-Content cmdlet.
This is more concise:
(gc $BaseLineFile)| % {$_.trim()} | sc $BaseLineFile
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With