2012-10-23 39 views
1

我尝试解析一些文本文件,并在年底,我需要做1号线从2号线:PowerShell的 - 连接字符串

19.10.2012 15:33:22<TAB here!> 
textline<TAB here!>#1 
19.10.2012 15:33:13<TAB here!> 
textline<TAB here!>#2 
19.10.2012 15:29:29<TAB here!> 
textline<TAB here!>#3 
19.10.2012 15:29:23<TAB here!> 
textline<TAB here!>#4 

在输出端我需要这样的:

19.10.2012 15:33:22<TAB here!>textline<TAB here!>#1 
19.10.2012 15:33:13<TAB here!>textline<TAB here!>#2 
19.10.2012 15:29:29<TAB here!>textline<TAB here!>#3 
19.10.2012 15:29:23<TAB here!>textline<TAB here!>#4 

请帮帮我! :)

编辑:这是我:

Get-ChildItem $Path -Recurse -Include *.* | Foreach-Object {$_.FullName} | 
Foreach-Object { 
    Write-Host $_ 
    $Item = Get-Item $_ 
     (Get-Content $_ -ReadCount 2 -Encoding UTF8) | Foreach-Object { 
     (-join $_)}} | Set-Content $Item -Encoding UTF8 
+1

我不使用PowerShell,但[标签]在”查找/替换[回车]“会做到这一点。最简单的非自动化方式是在MS Word中打开文件,并用“^ t”替换“^ t^p”。大多数优秀的代码编辑器也接受正则表达式或接近等价。 linux/unix中的'sed'也很容易。 – Marc

回答

3
Get-Content test.txt -ReadCount 2 | 
Foreach-Object { (-join $_) -replace '<TAB here!>',"`t" } 
+0

谢谢!使用您的代码! – tiv

0

一个办法:

$g = @() 
$a = gc .\yourTXTfile.txt 

for ($i=0; $i -lt $a.count ; $i+=2) 
{ $g += $a[$i]+$a[$i+1] } 

$g | set-content .\yournewTXTfile.txt 
+0

谢谢,你能告诉你如何在这个结构中包含脚本:'Get-ChildItem $ Path -Recurse -Include *。* | Foreach-Object {$ _。FullName} | ((Get-Content $ Item -Encoding UTF8)-Replace'\ d +。\ d +。\ d + \ d +:\ d +:Foreach-Object { \t Write-Host $ _ $ Item = Get-Item $ _ \ d + \t \ n','\ d +。\ d +。\ d + \ d +:\ d +:\ d + \t')| Out-File $ Item -Encoding UTF8 }'我尝试通过删除EOL字符来实现。(请参阅“... - 替换... – tiv