locked
Convert txt file to csv file with header RRS feed

  • Question

  • I have a txt file with below format. I want to convert this file as a csv file also i need to update header in csv file
    for eg:- Employee ID|Legacy ID|Cost Center|User Account
    btw first line is blank on this txt file

    00005|||Assembler Trainee|user1
    00006|||Assembler Trainee|User2
    00007|||Assembler Trainee|User3


    End result should be like this

    Employee ID|Legacy ID|Cost Center|User Account
    00005|||Assembler Trainee|user1
    00006|||Assembler Trainee|user2
    00007|||Assembler Trainee|user3

    Regards, Nidhin.CK

    Friday, December 30, 2016 5:03 AM

Answers

  • Did you try Import-CSV? There are parameters exactly for what you want

    Import-Csv -Delimiter '|' -Path YourFileNameHere -Header 'Employee ID','Legacy ID','Cost Center','User Account'
    BTW: I think your header count does not match the row count of your file


    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''


    • Edited by BOfH-666 Friday, December 30, 2016 5:15 AM
    • Proposed as answer by jrv Friday, December 30, 2016 5:58 AM
    • Marked as answer by Nidhin CK Friday, December 30, 2016 6:23 AM
    Friday, December 30, 2016 5:12 AM

All replies

  • Did you try Import-CSV? There are parameters exactly for what you want

    Import-Csv -Delimiter '|' -Path YourFileNameHere -Header 'Employee ID','Legacy ID','Cost Center','User Account'
    BTW: I think your header count does not match the row count of your file


    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''


    • Edited by BOfH-666 Friday, December 30, 2016 5:15 AM
    • Proposed as answer by jrv Friday, December 30, 2016 5:58 AM
    • Marked as answer by Nidhin CK Friday, December 30, 2016 6:23 AM
    Friday, December 30, 2016 5:12 AM
  • 'row count' should read 'column count'


    \_(ツ)_/

    Friday, December 30, 2016 5:58 AM