Solved

Convert CSV

Posted on 2013-05-18
9
434 Views
Last Modified: 2013-05-18
Hi,

i've a csv it looks like that:

UserId;OrderIdent;OrderID;Action;Product;Version
Z528517;2397277;ZP145676-001;YES;MAIL;MSC
Z528516;2397278;ZP145676-002;YES;MAIL;MSC
Z528515;2397279;ZP145676-003;YES;MAIL;MSC
Z528514;2397281;ZP145676-004;YES;MAIL;MS2003
Z528484;2397284;ZP145677-001;YES;MAIL;MSC
Z528474;2397285;ZP145677-002;YES;MAIL;MSC
Z528396;2397345;ZP145687-003;YES;MAIL;MS2003
Z130561;2397436;ZP145706-001;YES;MAIL;MSC
Z527465;2397632;ZP145766-001;YES;AdA
Z527465;2397633;ZP145766-002;YES;MAIL;MSXC2010
Z831113;2397637;ZP145767-001;YES;AdA
Z831113;2397638;ZP145767-002;YES;MAIL

Open in new window


I want to convert and sort it to this form (The last lines should be "AdA" and "MS2003"
to use it for some automatic exchange and AD coding



UserId,OrderIdent,OrderID,Action,Product,Version
Z528517,2397277,ZP145676-001,YES,MAIL,MSC
Z528516,2397278,ZP145676-002,YES,MAIL,MSC
Z528515,2397279,ZP145676-003,YES,MAIL,MSC
Z528484,2397284,ZP145677-001,YES,MAIL,MSC
Z528474,2397285,ZP145677-002,YES,MAIL,MSC
Z130561,2397436,ZP145706-001,YES,MAIL,MSC
Z527465,2397633,ZP145766-002,YES,MAIL,MSC
Z831113,2397638,ZP145767-002,YES,MAIL,MSC
Z528514,2397281,ZP145676-004,YES,MAIL,MS2003
Z528396,2397345,ZP145687-003,YES,MAIL,MS2003
Z527465,2397632,ZP145766-001,YES,AdA
Z831113,2397637,ZP145767-001,YES,AdA

Open in new window


Who can help here?

Thank you so much
0
Comment
Question by:Mandy_
[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
  • 4
  • 3
  • 2
9 Comments
 
LVL 19

Expert Comment

by:Raheman M. Abdul
ID: 39177054
Try the following:
import-csv H:\filecsv.csv | Sort-Object version -Descending | ft -AutoSize

your source data does not match with the resultant data what you require  as per your question.

Or try: import-csv H:\filecsv.csv | Sort-Object Product, version -Descending | ft -AutoSize
0
 
LVL 19

Expert Comment

by:Raheman M. Abdul
ID: 39177055
import-csv H:\filecsv.csv | Sort-Object version -Descending | ft -AutoSize | export-csv H:\ filecsv2.csv
0
 
LVL 19

Expert Comment

by:Raheman M. Abdul
ID: 39177067
The above code works if you replace all the ; with commas
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 70

Accepted Solution

by:
Qlemo earned 500 total points
ID: 39177311
marahman3001,

don't use format-* if exporting to CSV. The format cmdlets convert anything into a single string per line, destroying object structure and properties.
And *-csv has a delimiter parameter to tell which one to use ;-).


Mandy_,

I'm not certain about the proper order of rows you demand, but I would go with
(import-csv -delimter ';' file.csv | sort product, version -descending |
   converto-csv -notype -delimiter ';') -replace '"' | out-file result.csv

Open in new window

export-csv and convertto-csv add double quotes to each field, so we have to remove those to keep the original format.
0
 
LVL 2

Author Comment

by:Mandy_
ID: 39177321
hi,

thanks. sorry so far not working for me

What exactly did  ft -AutoSize
0
 
LVL 19

Expert Comment

by:Raheman M. Abdul
ID: 39177333
It's short form for format-table
Autosize displays the data in columns with automatic width according to the data

I guess your input data sample is not matching with the output you require. There must be error in typo etc.
Eg. Msxc2010  it's not in your output
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 39177368
Mandy_,

If something does not work for you, please tell us what did not work - e.g. list the expected result and what you got instead. And it is always a good idea to mention which post you refer to.
0
 
LVL 2

Author Comment

by:Mandy_
ID: 39177486
Thank you for your help. this one below is working fine.


(import-csv -delimter ';' file.csv | sort product, version -descending |
   converto-csv -notype -delimiter ';') -replace '"' | out-file result.csv
0
 
LVL 2

Author Closing Comment

by:Mandy_
ID: 39177487
very good . thank you
0

Featured Post

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

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).
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
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…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 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