Powershell Regex:仅用制表符替换多个空格 [英] Powershell Regex: Replace only multiple spaces with tabs

查看:45
本文介绍了Powershell Regex:仅用制表符替换多个空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个 Powershell 问题,类似于这个 C# 问题中提出的问题:C#问题链接

This is a Powershell question similar to what was being asked in this C# question: C# Question Link

我在可变长度的文本文件中有固定宽度的列数据,所以我想用制表符分隔数据.为此,我想使用 Powershell 读取文件,使用 Regex 表达式仅用制表符替换多个空格,保持行尾完整并将其输出到临时文件.然后我会将其重命名为原始名称.

I have fixed width column data in a text file that are of variable length, so I'd like to delimit the data with tabs. To do so, I want to use Powershell to read in the file, replace only multiple spaces with tabs using a Regex expression, keep the end of lines intact and output it to a temp file. I'll then rename it to the original.

我在网上搜索过,似乎只能找到一些零碎的东西.对此的任何帮助将不胜感激!

I've searched the web and only seem to be able to find bits and pieces. Any assistance with this would be greatly appreciated!

推荐答案

try

gc .\0.txt  | 
 % { $_ -replace '  +',"`t" } |   
     set-content .\temp.txt

这篇关于Powershell Regex:仅用制表符替换多个空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆