Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Powershell  script fix

Posted on 2014-03-26
8
Medium Priority
?
325 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 71

Accepted Solution

by:
Qlemo earned 2000 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
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 
LVL 5

Author Closing Comment

by:magento
ID: 39956769
Thanks for the pointer .
0
 
LVL 71

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 71

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Loops Section Overview

971 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