?
Solved

Powershell  script fix

Posted on 2014-03-26
8
Medium Priority
?
322 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 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
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 Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

719 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