Working with CSV files -Powershell

Hello all,
             Here is a senario where am struck for past 2 days and i thought some one here can help.
I am trying to get unique lines out of a csv file based on one particular column. Lets take a rough example , below is a sample csv i have pasted.. where i need to get only one last row from each category
Problem
Severity
Category
1
Warning
Event
2
critical
Alert
3
Warning
Alert
4
Warning
Event
5
Warning
Alert
So the end result should have the complete row of problem 4&5 as that is the last appearing of unique data. Just to add an information that my csvhas 25 columns and as big as 11MB of data. Any thoughts would be greatly appreciated.
S.Arun Prasath HP ARDE TEAM

If I understand your scenario, this does the job...
$testdata=import-csv 'c:\temp\test.csv'
$categories=$testdata | Select Category -Unique
foreach($cat in $categories){
$testdata | Where-Object{$_.Category -eq $cat.Category} | Select -Last 1
Result:
Problem                                                  
Severity                                                
Category                                               
4                                                        
Warning                                                 
Event                                                  
5                                                        
Warning                                                 
Alert  
Just a humble SysAdmin

Similar Messages

  • Help working with CSV files

    I have a CSV file with 3 columns
    Jobtitles-----ADRole1----- AdRole2
    title1---------Role1---------Role4
    title2---------Role2---------Role5
    title2---------Role3--------Role6
    And i also have a list of Active Directory Users in other variable $users.
    I need to get the AD users which jobtitle match the ones in the first column of the csv "jobtitles"
    I do it like:
    import-module activedirectory
    $csv2= Import-Csv e:\mycsv.csv | Select-Object JobTitles
    $Jobtitles = @()
    foreach ($line in $csv2) {
    $Jobtitles += $line.title
    $users = foreach ($user in $result){
    get-aduser $user.loginname -properties title, samaccountname
    foreach ($User in $Users) {
    if ($Jobtitles -contains $User.title) {
    write-host $User.samaccountname $User.title
    This works fine.
    What i don't know how to do is reference the same row in the csv
    For example if the user jobtitle matches title1, add the user to the AD group Role1 and Role4 (because it is in the same row as those roles)
    Any idea?
    thanks

    In the second line in your script, the " | select-object jobTitles" causes only the data from the jobTitles column in the .CSV file to be included in the array of objects stored in the $csv2 variable. If you avoid doing that, then all of the data from the
    .CSV file will be present in $CSV.
    But I don't think the code as shown "works fine". In the first foreach statement, your code references a property called .title, whereas the only property in $csv would appear to be .jobTitles. But, if it had been coded correctly, this would be a wasted
    step, as it seems only intended to create another array of "title" values, which you already have in $csv2.
    then the second foreach processes data in an undefined array called $result.
    With these issues, it is a little difficult to determine what actually happens in the following code.
    I'd suggest you give it another try then copy/paste the complete code for us to comment on.
    Al Dunbar -- remember to 'mark or propose as answer' or 'vote as helpful' as appropriate.

  • Working with CSV files in Numbers 09

    I'm able to import CSV files into Numbers '09 but the CSV file has multiple categories in each column. I want to SUM just one section and put the result in a summary chart but don't how to limit the SUM to just one of the groups in the column. The number of the rows is constantly changing with each import but the data that I want to use is always in column G. I would like to be able to just import the updated CSV file without having to manual select the cells I want to use each time. Any ideas? Thanks.

    If you took care to use the Numbers's vocabulary, things would be easier.
    You import datas upon vehicle 1 in table 1, not in sheet 1.
    If you really use the import feature, you will get a new table name each time so the formula would be different each time.
    The good practice would be to create a table with 11 columns for each vehicle.
    In every cell of column K (the 11th one), the formula would be:
    =IF(ISERROR(VLOOKUP("Total Price",$G$1:G2,1,0)),"",IF(OR(G="Total Price",ISBLANK(G),NOT(ISERROR(VLOOKUP("type",$G$1:G2,1,0)))),"",1))
    Then, import the CSV,
    copy the newly created table's contents and paste it in the table dedicated to the vehicle.
    Delete the table created during the import process.
    Doing that,
    the cell dedicated to vehicle 1 in "Vehicle Expense Summary" would be :
    =SUMIF(vehicle1 :: K,">0",vehicle1 :: G)
    the cell dedicated to vehicle 2 in "Vehicle Expense Summary" would be :
    =SUMIF(vehicle2 :: K,">0",vehicle2 :: G)
    Yvan KOENIG (VALLAURIS, France) mercredi 3 mars 2010 19:04:30

  • Can I get pages to work with .csv files?

    I'm trying to use the pages mail merge feature! I have data in a CSV file and I'm on a mac using Pages.
    This is what I've discovered so far;
    Pages needs a .Numbers file to pull data from for the mail merge feature. So I take my CSV file, open it with numbers, save it as a .Numbers file and then go back to Pages to use the mail merge feature, but I get an odd error message, so I must not be converting right (or something).
    The error reads as follows; "Please select a Numbers document that has one or more named header columns and one or more rows of data." The CSV file has 20 contacts in it, so I'm not sure what it's asking for exactly, because in the .Numbers file I have 20 rows with data.
    Does anyone have any suggestions? Or perhaps they could point me to a reference manual of sorts?
    Thanks for your time!
    S.o.t.S.

    Thanks Jerrold, here's what I have.
    This is the Numbers document
    This is the Pages sheet
    These are the "options" selected for merging and then I click merge...
    and then the output of just one.

  • OmniPortlet - Working with CSV files

    Is it possible to filter a CSV file based on a Page parameter? It doesn't seem to work in my tests.
    If not, does anyone know an effective way to convert CSV/XLS to XML in row/rowset format? Perhaps using a pre-buils stylesheet that converts Excel XML to Rowset/Row?
    Any feedback greatly appreciated...

    Hello Stephen,
    The current OmniPortlet does not make any filtering. You can send some parameters in the URL or to a Web Service method but in this case the filter is made by the 'data source provider' itself, not by OmniPortlet.
    We will introduce filtering -for all data sources- in the next release of the OmniPortlet. (next PDK)
    Regards
    Tugdual Grall

  • Working with flat file as source in owb 10.2

    Hi,
    I am working with flat file as source . While validating the mapping i am getting the following error like
    " to specify a data file configure the mapping , add a node under ' Source data file', type in the file name
    and select the file location."
    Please give me the suggestion . It is very urgent.

    Hi Venkat,
    I tried the following stepts.
    1. in Design Center select your mapping and right click and select configure
    2. select sql loader data files and select create
    3. On right hand side data file Name : enter your source file name (ex : source.csv)
    4. click ok button.
    5. open mapping and validate.
    The mapping is validating. After validating I deployed the mapping. Up to this the mapping is working fine.
    But when I start the mapping, It has completed with errors.
    The error message is:
    Status
    Error Log
    RPE-01013: SQL Loader reported error condition, number 1.
    LRM-00112: multiple values not allowed for parameter 'control'
    Job Summary
    Updated : 2009-02-24 15:32:43.0 Job Final Status : Completed with errors Job Processed Count : 1 Job Error Count : 1 Job Warning Count : 0
    Please give me the suggestions.
    Thanks,
    Venkat

  • Has anyone not working with .dv files had synchronization problems?

    Has anyone not working with .dv files had sound synchronization problems? I'm not exactly sure what the alternatives to DV are, but I think one of them is HD.
    The reason for asking this question is to help isolate the nature and cause of a very serious flaw in iMovie '11. In the original release of iMovie '11 (version 9.0) there was a small--but serious--synchronization problem. In the 9.01 there is a large synchronization problem. We know of one person who has not experienced the problem, and he is not working with DV files (media). So we want to find out if anyone who is using something other than .dv files is experiencing a lack of synchronization between sound and picture. Knowing the answer to this will help with figuring out where the cause lies. For the initial iMovie '11 release (9.0), you probably would not notice a problem unless you had very long event-clips, e.g., two hours long. Events get this long if you are transferring from analog 8 mm tapes. Even then, it would have to be in scenes in which the connection between event and sound is obvious, e.g., close ups of people talking. It isn't until the 9.01 release that most people would notice anything. All we need to do is establish one case of a synchronization problem in which the person is using something other than DV.
    Message was edited by: Paul Bullen

    Hopefully, the 9.0.2 release will make my question moot. Zyfert must have posted the announcement of the release just as I was formulating my question. Still, if you have information on the subject, it would be interesting to hear.

  • Working with RAW files in PSE9:  Doable or better to use PSE12?

    I have PSE 9 and will soon get a camera with RAW capability.  I notice that Adobe no longer supports PSE 9.  Am I in for trouble if I don't upgrade to PSE 12 since I don't know how to work with RAW files?  It sounds as if I will need something to convert RAW files?  Where do I get it?  Is it a big deal for a beginner with no software skills?

    You can download a free DNG Converter from Adobe and then convert your RAWs to DNGs which can be used in PSE9.
    You don't need PSE12, but if you want to purchase PSE 12, you get the most current features in the Raw processor (which in my opinion is a huge improvement over what is available in PSE9), and you don't need the extra step of converting to DNG.

  • Very slow responce when working with Office file on DFS-Share

    Very slow responce when working with Office file on DFS-Share
    We have implemented the following configuration
    Domain level Windows 2000. Two member servers with Windows Server 2008 R2, sharing the same DFS namespace with, at the moment, one folder target called Home.
    Users complaining that the access to different MS Office files is very slow. Even creating a new MS Word document using right click context menu takes up to 4 minutes to open. Saving, for example, one singe Excel sheet takes also few minutes.
    Tested with both, MS Office 2007 and MS Office 2010. Makes no difference. When using Office 2010 you can see the message like contacting:
    \\DomainName\Root\Home\UserName. Other files like TXT, JPG or PDF are not affected.
     What makes the thing really weird is the fact, that the behavior described above can absolutely change after client machine being rebooted, suddenly everything becomes very fast and this condition can revert back again just after the next
    reboot.
    Considerations until now:
    1. This has nothing to do with the file size. Even tiny files are affected.
    2. AD Sites are configured correctly and the client workstations see themselves in the correct sites.
    3. This is not an Office issue. If I map my folder target not as DFS, but directly as shared network drive
    \\ServerName\Root\Home\UserName , everything functions as expected
    What makes me suspicious: when using f.e. TCPView to monitor connections, I can see, that each time I make any operation on an office file, there will be a connection established to one of the domain controllers, sometimes to remote ones,
    located in other countries. But on the other side, even if the connection is established to the nearest DC, operations are still very very slow!
    Just forget to say. All clients are Windows 7
    Thanks to all who respond.

    Dear all,
    sorry for the delayed reply. The problem has been solved now and since September 19<sup>th</sup>. everything is functioning as expected.
    What was done:
    Deleted replication targets excepting the initial ones
    Carefully recreated folder targets
    Deleted and recreated  replication groups
    Disabled SNP features on both namespace servers
    Created EnableTCPA registry entry
    Checked that the following Updates are installed
    http://support.microsoft.com/kb/2688074
    http://support.microsoft.com/kb/2647452
    Concering Office File validation KB2553065 - This Update was already declined on our WSUS server
    Kind Regards
    Eduard

  • Working with RAW files in iPhoto 5.0.4 and Elements 4.0.1

    I take photos in RAW mode and download them to iPhoto. When I try to edit the photo in iPhoto, the picture is a tiny little file that is impossible to enlarge with any sort of clarity. Also, the word "RAW" does not appear anywhere on the iPhoto window like I read it is supposed to.
    When I drag the file to Photoshop Elements, I get an editing window that has none of the tools usually associated with JPEG files. I get a separate window in which I can darken or lighten the image, that's it.
    Clearly, I'm doing something wrong. No one in their right mind would ever use RAW if this is how it works.
    Any ideas?

    Hi Jack!
    If you're new working with RAW files, your right, it just doesn't make sense. RAW <imho> is a bit overrated. One thing you will need to keep in mind when shooting in RAW, is you will still need to take a well exposed image. What RAW files will allow are CHANGES in all areas of the image v. JPEG which may allow you to ADJUST a few settings in the image. My only suggestion would be to kepp playing around with PSE until you get the hang of it, it is an excellent image editing software. But realize, a well exposed JPEG and RAW file are hard to tell apart...
    Personally, I do not directly download RAW files through iPhoto but will create a folder and download to here, and simply drage folder to iPhoto to import (which are then 'converted' into JPEG files). This way I have the original RAW images safely located outside of iPhoto as well as in iPhoto. You should set Elements as your choice of application to edit files inside iPhoto.
    Good luck, Rick
    Good link: http://www.elementsvillage.com/forums/ and just for fun: http://www.photoshopcosmetics.com/index.php

  • Working with Large files in Photoshop 10

    I am taking pictures with a 4X5 large format film camera and scanning them at 3,000 DPI, which is creating extremely large files. My goal is to take them into Photoshop Elements 10 to cleanup, edit, merge photos together and so on. The cleanup tools don't seem to work that well on large files. My end result is to be able to send these pictures out to be printed at large sizes up to 40X60. How can I work in this environment and get the best print results?

    You will need to work with 8bit files to get the benefit of all the editing tools in Elements.
    I would suggest resizing at resolution of 300ppi although you can use much lower resolutions for really large prints that will be viewed from a distance e.g. hung on a gallery wall.
    That should give you an image size of 12,000 x 18,000 pixels if the original aspect ratio is 2:3
    Use the top menu:
    Image >> Resize >> Image Size

  • Unexpected problem: uncaught exception when working with audio files in Soundtrack Pro

    Hey,
    Whenever I double click an audio file in the timeline to work on it, I end up getting the Error message: "Unexpected problem: uncaught exception" and Soundtrack Pro eventually crashes.  Also, this happens when I try to work with audio files in the file editor.  I have Leopard and am using Logic Studio 8.  Any insight would be much appreciated. Thanks
    Matt

    Didnt know how to remove the original clip from the STP arrange window - or whatever it's called in STPro.  So I could go no further in my perverse science experiment. 
    It also appeared that I could only import an aif but not a wav? 
    I gave up on STPro and did what I needed to do in Logic, which I use regularly.    
    Thank you for folowing up on this. 
    PS.  I used to use an old PowerPC version (1.0.3) of STPro and loved the way it visually showed the change in the waveform when you added each efffect.  It appears that the new version (3.0.1) does not allow you to do this anymore?  You can render or flatten the effects to see the final waveform, but then you are dead in the water and cant make changes?  
    Im such a newbie at STPro that I am probably not using it right? 

  • Working with Multiple Files in Workspace Layout

    If I was working with multiple files in the workspace layout, they each used to be available for selection from a tab.  Now I can either cascade the files horizontally or vertically - but not have them appear in a tab across the top of the workspace layout.
    Does anyone know how to set the workspace to present multiple files in tabs?  I have CS3.

    Tanya,
    This may not help, but the times when that happens to me is when I go too fast and some operations haven't finished. I then try to select a file that hasn't completed and the file I select is in the process of having the data updated. The worst is when it is trying to render as I am doing something.
    I hope this helps some.
    Mel

  • Help: Working with .MOV files in FCP and forced to RENDER FOR EVERY EDIT

    I'm working with .MOV files from my digital camera in Final Cut Pro and every time I make a new edit, I have to render it in order to see it in the canvas.
    How do I make it so that I don't have to render every edit in order to see it?
    (I've worked with files straight from a DV camera, and editing went fine. I'm assuming it has to do with the .MOV files)

    DV Cameras are not the same thing as a Digital camera. Digital cameras offer video on a limited basis and it's usually highly compressed in a non-editing format such as MPEG-2 or similar. NLEs are made to work with video cameras, not still cameras which is why you're having trouble.
    That's not to say you can't edit video captured with a digital camera, but you need to know how to prep it for editing. Some digital cameras shoot at odd frame rates and they all use some form of compression that is not typically used in editing. This means that you'll likely need to convert your clips to an editable format first using Compressor.
    Andy

  • How Can I Work With PHTML Files In Dreamweaver ??

    I want to work with PHTML files in Dreamweaver CS3 - How do I
    go about getting this to work?

    The solutions is either of the following:
    Adobe Lightroom - Find moved or missing files and folders
    Copy the photos back into the exact same folder and folder location that they were in before
    I don't know what you actually did "when I pasted it back" ... but the bigger issue is that you shouldn't be working with these files in your operating system, period. Once you import them into Lightroom, you don't manage these files in your operating system.

Maybe you are looking for

  • RFC Adapter  RFC to File

    Hi, Can somebody help me to view this thread. I am learning XI using RFC to File and I have got some difficulties in undestanding the Adapter Configuration. /people/michal.krawczyk2/blog/2005/03/29/configuring-the-sender-rfc-adapter--step-by-step fro

  • N70 - Multimedia Key - Fault?

    Hi All, I have set the Notes application to the Multimedia Key, which worked for a while, but then stopped. This is my second N70 due to o2 blocking my first for some reason only known to themselves. The Multimedia Key on the first didn't work at all

  • How to cd to a directory that contains spaces in the name

    A brain dead application has created a directory hierarchy that contains white spaces in the directory path. For example: /first_dir/second dir/third dir/filename. I want to look at the file from the command line via iTerm/Terminal but I can not get

  • Navigation with widgets

    For my courses, I have put navigation widgets on the master slide and disabled the playbar. One widget tells the page to go to the next slide, the other tells it to go to the previous slide. This works fine until I click the Back widget and then the

  • My iTunes is not connecting to iTunes stores? So what shell I do??

    my itunes is not be able to connect to iTunes stores?