Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Convert CSV

Posted on 2013-05-18
9
Medium Priority
?
437 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 71

Accepted Solution

by:
Qlemo earned 2000 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 71

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

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

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
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…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

704 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