Solved

Powershell  script fix

Posted on 2014-03-26
8
318 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 70

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
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
LVL 5

Author Closing Comment

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

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 70

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

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…
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

632 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