Reputation: 31
I need to specify the line lenght with powershell. I have a source file with lines with different line lenghts and i need to export them to a new file with all the same line lengths, 470. I found a command but this will add some with spaces in front of the line and i need to add the spaces at the end of the line.
$sourcefile = '.\file.txt'
foreach ($row in $sourcefile) {
$row = [string]::Format("{0,469}",$row) | out-file '.\newfile.txt' -append }
Upvotes: 0
Views: 462
Reputation: 109045
Use a negative number to specify left alignment in a given space.
Eg.
'#{0,-10}#' -f 43
outputs:
#43 #
Upvotes: 3