Solved

Convert CSV

Posted on 2013-05-18
9
431 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_
  • 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to set a value in extensionAttribute AD attribute by PowerShell? 11 42
Powershell - Get lastLogon 4 27
Powershell - Script Refine - v3 8 41
Debug script powershell wmi 3 15
Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
This article will help you understand what HashTables are and how to use them in PowerShell.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
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…

856 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