Solved

Convert CSV

Posted on 2013-05-18
9
432 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 69

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 69

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Set OWA language and time zone in Exchange for individuals, all users or per database.
A procedure for exporting installed hotfix details of remote computers using powershell
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
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…

756 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