手机
当前位置:查字典教程网 >脚本专栏 >PowerShell >Powershell小技巧之去除多余的空格
Powershell小技巧之去除多余的空格
摘要:要去去除多余的空格,请尝试下面正则表达式:PS>'[Man,itworks!]'-replace's{2,}',''[Man,itworks...

要去去除多余的空格,请尝试下面正则表达式:

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版本

【Powershell小技巧之去除多余的空格】相关文章:

Powershell小技巧之查询AD用户

PowerShell中定义多行字符串变量的方法

Powershell小技巧之设置IE代理

Windows Powershell 变量的幕后管理

Powershell创建数组正确、更快的方法

Powershell小技巧之删除不规则字符

PowerShell小技巧之查找获取注册表路径

Powershell小技巧之使用Jint引擎在PowerShell中执行Javascript函数

Powershell小技巧之判断是否包涵大小写

Windows Powershell排序和分组管道结果

精品推荐
分类导航