1

I try to parse some text files, and at the end I need to make 1 line from 2 lines:

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

At the output I need to have this:

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

Help me please! :)

EDIT: This is what I have:

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
  • 1
    I don't use powershell, but a find/replace on "[tab][carriage-return]" would do it. Easiest non-automated way is to open files in MS Word and replace "^t^p" with "^t". Most good code editors also accept regex or near equivalents. sed in linux/unix would be easy too. Commented Oct 23, 2012 at 14:20

2 Answers 2

3
Get-Content test.txt -ReadCount 2 | 
Foreach-Object { (-join $_) -replace '<TAB here!>',"`t" }
Sign up to request clarification or add additional context in comments.

Comments

0

One Way:

$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

1 Comment

Thanks, can you tell how to include your script in this construction: Get-ChildItem $Path -Recurse -Include *.* | Foreach-Object {$_.FullName} | Foreach-Object { Write-Host $_ $Item = Get-Item $_ ((Get-Content $Item -Encoding UTF8) -Replace '\d+.\d+.\d+ \d+:\d+:\d+ \n', '\d+.\d+.\d+ \d+:\d+:\d+ ') | Out-File $Item -Encoding UTF8 } I try do so by remove EOL characters.. (See after "... -Replace ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.