开发者

How to remove extra space between columns in Powershell Format-Table

I'm converting some csv data to a file format that expects values a certain positions in a line. I thought I'd use format-table to accomplish this by setting the column widths. However, this adds an unwanted extra space between columns. Is there a way to remove the space or are there other formatting optio开发者_开发知识库ns that I could use?

$format = 
@{E={$_.lname}; width=30},
@{E={$_.fname}; width=30},
@{E={$_.dob}; width=8},
@{E={if($_.sex -eq 'F') { 'V' } elseif($_.sex -ne 'M') { 'O' } else { $_.sex} }; width=1},

...

@{E={if($_.mstatus -eq 'M') {'Y'} else {'N'}}; width=1;},
@{E={$_.social}; width=50};

import-csv -Delimiter '|' .\data.txt | ft $format -hidetableheaders | out-file -width 2500 'c:\temp\temp.txt'


There's not a way to get rid of the extra space output by Format-Table AFAIK. Try outputting as a string e.g.:

... | Foreach { '{0,-30}{1,-30}{2,-8}' -f $_.lname, $_.fname, $_.dob }

Note that this is a .NET formatting string and all the normal .NET formatting directives apply.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜