![](/img/trans.png)
[英]Powershell Format-Table with new line break adds extra space between column
[英]How to remove extra space between columns in Powershell Format-Table
我正在将一些csv数据转换为一种文件格式,期望值在一行中的某些位置。 我以为我会使用format-table来设置列宽。 但是,这会在列之间添加不必要的额外空间。 有没有办法删除空间或有其他格式选项,我可以使用?
$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'
没有办法摆脱Format-Table AFAIK的额外空间输出。 尝试输出为字符串,例如:
... | Foreach { '{0,-30}{1,-30}{2,-8}' -f $_.lname, $_.fname, $_.dob }
请注意,这是一个.NET格式化字符串,并且适用所有正常的.NET格式化指令 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.