Solved

Powershell  script fix

Posted on 2014-03-26
8
309 Views
Last Modified: 2014-03-26
Hi ,

EE experts helped on my question.
http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_28396033.html

In columnB i have all lines of a txt file except first line.
The original txt file has line breaks,
The new csv file do not. It's just one long piece of text . Can you please advice whether we can fix it?


get-childitem 'C:\EE\FOLDER\' |
  ? { $_.PsIsContainer } | % {
    $folder = $_.FullName
    get-childitem $folder -Filter *.txt | % {
      $content=Get-Content $_.FullName
      $colA = $content | select -first 1
      $colB = $content | Select -Skip 1
      if ($colB[0].Length -lt 10 -and $colB[0] -match '\w+\.[XVI]+\.\d+')
      {
         $colA += ' ' + $colB[0]
         $colB = $colB[(-$colB.Count+1)..-1]
      }
      New-Object PsObject -Property @{
         ColumnA= $colA -replace 'AuthorName', ''
         ColumnB = $colB -join ' ' }
    } | export-csv "C:\EE\FOLDER\$(Split-Path -leaf $folder).csv" -NoTypeInformation -Encoding UTF8
  }

Open in new window


Thanks
0
Comment
Question by:magento
  • 5
  • 3
8 Comments
 
LVL 68

Accepted Solution

by:
Qlemo earned 500 total points
ID: 39956674
Change line 15 to
         ColumnB = $colB -join '`n' }

Open in new window

to retain all carriage returns.
0
 
LVL 5

Author Comment

by:magento
ID: 39956697
Hi,

I tried the above but get the value instead .. I used backtip n

eg: Dr. Dominik Waldvogel`nRaub`n2012
0
 
LVL 5

Author Comment

by:magento
ID: 39956704
Tried double quote and it seems working, let me check all files and let you know.

ColumnB = $colB -join "`n" }

Open in new window

0
 
LVL 5

Author Closing Comment

by:magento
ID: 39956769
Thanks for the pointer .
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 68

Expert Comment

by:Qlemo
ID: 39956899
Oh, sorry, of course you need to use double quotes instead of single quotes. Stupid beginner's mistake.
0
 
LVL 5

Author Comment

by:magento
ID: 39956921
I am afraid , if you are beginner ..What am i ???
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 39956938
I'm not a beginner for sure, but still making mistakes like one ;-). This is one "habit" I don't get out of my way.
0
 
LVL 5

Author Comment

by:magento
ID: 39956949
I know for sure you are not a beginner . Getting rank of Prodigy is not possible without great skills. Thanks for your help.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Synchronize a new Active Directory domain with an existing Office 365 tenant
A procedure for exporting installed hotfix details of remote computers using powershell
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now