none
How to read csv files -help with logic RRS feed

  • Question

  • Hi,
    I need your help to build a logic for me in powershell.This is my requirment.
    I have a location $sourceDirHR="D:\MFT\PSHRIn\ where all the .csv files are kept.suppose there are 6 csv files kept with name like apple.csv,bat.csv,salt.csv,apple_control.csv,bat_control.csv,salt_control.csv
    below I am taking one csv file for example and letting you know the content of it:
    apple.csv contains data like 1,2,334,34,35
                                 345456,65,7,67,66,7
    apple_csv contains data like 091011,1212,2    ie date,time,noofrecords where no of records will be like in this case 2 as apple.csv contains 2 records.Had apple.csv contained 5 enteries then apple_control.csv will be 091011,1212,5
    I have to apply a logic that from location $sourceDirHR  ,it reads all csv files and and compare filesnames first ie apple.csv with apple_control.csv ,bat.csv with bat_control.csv etc etc..
    once comparsion is successful then it should count the no of records in apple.csv (in our case 2) and compare it with the last column of apple_control.csv which has also 2.
    if this comparsion is true.it just write a simple print statement "file sent is correct "..
    can any one help me this ..?
    Saturday, August 20, 2011 4:02 PM

Answers

  • Hi,

    Ok, read the CSV File

    $content = import csv <filename>

    now count the rows

    $rows=$content | measure-object -line

    now you have to substract one for the headerline

    $rows = $rows -1 (or; $rows--)

     

    What do yu mean with "compare filenames first"?


    regards Thomas Paetzold visit my blog on: http://sus42.wordpress.com
    Monday, August 22, 2011 8:11 AM

All replies

  • Hi,

    Ok, read the CSV File

    $content = import csv <filename>

    now count the rows

    $rows=$content | measure-object -line

    now you have to substract one for the headerline

    $rows = $rows -1 (or; $rows--)

     

    What do yu mean with "compare filenames first"?


    regards Thomas Paetzold visit my blog on: http://sus42.wordpress.com
    Monday, August 22, 2011 8:11 AM
  • hi,

    is you question answered or have you got any updates on this topic for me?

    If it is answered, it would be great if you mark it as answered. This can be beneficial to other community members reading the thread.

    Thank´s a lot in advance


    regards Thomas Paetzold visit my blog on: http://sus42.wordpress.com
    Friday, August 26, 2011 5:20 AM