Solved

Powershell  script fix

Posted on 2014-03-26
8
305 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

14 Experts available now in Live!

Get 1:1 Help Now