Setting Fields in a File as Variables

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 5 years, 7 months ago.

  • Author
    Posts
  • #5797

    by pitccorp01 at 2013-04-11 12:59:28

    Hi,

    I have an input file that has two fields without headings separated by whitespace, where the first field contains names and the second field contains numbers. For example,

    [quote]
    Anthony 14
    Mike 9
    John 21
    Sally 10
    Mary 9
    Jenefer 71
    [/quote]

    How can I write a Powershell script that will loop through the input file and set each line (n) of the first field as $NAME.n and each line (n) of the second field as $NMBR.n, where .n=line count?

    Thanks

    by Nobody at 2013-04-11 13:16:44

    Try this


    $input = ".\testdata.txt"
    $data = import-csv -path $input -delimiter " " -header "name","number"
    $data

You must be logged in to reply to this topic.