Powershell小技巧之去除多余的空格
要去去除多余的空格,请尝试下面正则表达式:
PS> '[ Man, it works! ]' -replace '\s{2,}', ' '
[ Man, it works! ]你也可以用这个方法转换成固定格式的CSV表格:
PS> (qprocess) -replace '\s{2,}', ','
>tobias,console,1,3876,taskhostex.exe
>tobias,console,1,3844,explorer.exe
>tobias,console,1,4292,tabtip.exe一旦变成CSV格式,你就可以使用ConvertFrom-Csv获取该文本数据的对象:
PS> (qprocess) -replace '\s{2,}', ',' | ConvertFrom-Csv -Header Name, Session, ID, Pid, Process
Name : >tobias
Session : console
ID : 1
Pid : 3876
Process : taskhostex.exe
Name : >tobias
Session : console
ID : 1
Pid : 3844
Process : explorer.exe
Name : >tobias
Session : console
ID : 1
Pid : 4292
Process : tabtip.exe
(...)支持所有PS版本
相关推荐
higheels 2020-08-03
ZoctopusD 2020-08-03
酷云的csdn 2020-08-03
higheels 2020-07-27
liushun 2020-06-28
zhendeshifeng 2020-06-22
Sabrina 2020-06-11
CARBON 2020-06-03
CARBON 2020-06-01
DBATips 2020-05-31
higheels 2020-05-29
applecarelte 2020-04-15
Yyqingmofeige 2020-03-28
yoshubom 2020-03-06
Yyqingmofeige 2020-03-02
SciRui 2020-02-26