Export CSV Cmdlet goes to infinite loop

This topic contains 4 replies, has 3 voices, and was last updated by Profile photo of Vimal Sreedhar Vimal Sreedhar 2 years, 5 months ago.

  • Author
    Posts
  • #16508
    Profile photo of Vimal Sreedhar
    Vimal Sreedhar
    Participant

    I'm trying to aggregate data from various CSV's into one using the following line of code

    “ ls -n *.csv | %{ ipcsv $_} | epcsv allinone.csv -NoTypeInformation “

    It worked fine until I changed the exported csv name to OneWorldFile.csv. It looks like PS lands into an infinite loop and appends the data into the CSV. I'll have to eventually halt the process.

    “ ls -n *.csv | %{ ipcsv $_} | epcsv OneWorldFile.csv -NoTypeInformation “

    Here is the screenshot for your verification : http://note.io/1pNoee3. Is there any reason for this behaviour? Did I miss something?
    Thank you in advance for your reply.
    Vimal.

  • #16509
    Profile photo of Vimal Sreedhar
    Vimal Sreedhar
    Participant

    Also, I happened to notice that this behaviour happens only if the resultant CSV starts with the name of any other existing csvs inside the directory. Yes, I don't face any problems if I export the aggregate CSV to another directory.

  • #16526
    Profile photo of Mike F Robbins
    Mike F Robbins
    Participant

    Seems to be an issue with pipeline input for Import-Csv. I can replicate the issue. The issue doesn't occur when I provide the items to Import-Csv via parameter input instead of pipeline input.

    Import-Csv -Path (Get-ChildItem -Name *.csv) | Export-Csv -Path .\OneWorldFile.csv -NoTypeInformation
    
  • #16530
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    As long as you exclude your output file from Get-ChildItem, I suspect it'll work either way.

    ls -n *.csv -ex OneWorldFile.csv | %{ ipcsv $_} | epcsv OneWorldFile.csv -NoTypeInformation
    
  • #16536
    Profile photo of Vimal Sreedhar
    Vimal Sreedhar
    Participant

    Thank you, Mike and Dave.

You must be logged in to reply to this topic.