Setting Fields in a File as Variables

Welcome Forums General PowerShell Q&A Setting Fields in a File as Variables

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

  • Author
  • #5797

    Points: 0
    Rank: Member

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


    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,

    Anthony 14
    Mike 9
    John 21
    Sally 10
    Mary 9
    Jenefer 71

    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?


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

    Try this

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

The topic ‘Setting Fields in a File as Variables’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort