Get data from string and output

Welcome Forums General PowerShell Q&A Get data from string and output

Viewing 8 reply threads
  • Author
    Posts
    • #277539
      Participant
      Topics: 2
      Replies: 8
      Points: 30
      Rank: Member

      I’m reading a text file looking for a string that start with $X. When I find that string I want to get the next 7 positions from
      that string. The values in file are separated by a comma.

      example:

      $M00000000,$F000000,$J08,$V1000,$f000000,$m0001274,$n0001274
      $Z,$I RW6 ,$N 1 ,$G201120,$H141340,$M00000000,$F000000,$X0000001240,$U0000

      I want to get the 0000001240 value in a variable.

      Thanks.

       

      • This topic was modified 1 month, 1 week ago by grokkit.
      • This topic was modified 1 month, 1 week ago by AndyH45.
    • #277650
      Participant
      Topics: 1
      Replies: 96
      Points: 440
      Helping Hand
      Rank: Contributor

      I don’t understand the “7 positions” requirement as your desired result doesn’t seem to show that.

    • #277665
      Participant
      Topics: 2
      Replies: 8
      Points: 30
      Rank: Member

      Could it be checked by line?

      foreach ($linelvl in $lines)

       

      Thx.

       

    • #277677
      Participant
      Topics: 1
      Replies: 96
      Points: 440
      Helping Hand
      Rank: Contributor

      Sure, but Select-String -Path without -Raw switch does read line by line already.

    • #277686
      Participant
      Topics: 2
      Replies: 8
      Points: 30
      Rank: Member

      Sorry, I was trying to get just that value in a variable I could use in an ouput.

      something like:

      $wo =  ($linelvl | Select-String -Pattern ‘(?<=\$X).*?(?=,)’).Matches.Value
      Thx again.

    • #277704
      Participant
      Topics: 2
      Replies: 8
      Points: 30
      Rank: Member

      This is my full script, and I’m trying to add the Value from the $X string to my last field of my output.

      THanks… hope this helps explain better what I’m trying to achive.

       

    • #277713
      Participant
      Topics: 2
      Replies: 8
      Points: 30
      Rank: Member

      The last line of the files contains the $X, but I strip that line before writing the output. I need to somehow capture that
      value before I remove that line during my output write.

      sample data from a file.
      $M00000000,$F000000,$J08,$V1000,$f000000,$m0000000,$n0000000
      $M00000000,$F000000,$J08,$V1000,$f000000,$m0000000,$n0000000
      $M00000000,$F000000,$J08,$V1000,$f000000,$m0000000,$n0000000
      $M00000000,$F000000,$J08,$V1000,$f000000,$m0001274,$n0001274
      $Z,$I RW6  ,$N   1  ,$G201120,$H141340,$M00000000,$F000000,$X0000001240,$U0000

    • #277731
      Participant
      Topics: 17
      Replies: 1951
      Points: 3,987
      Helping Hand
      Rank: Community Hero

      Here are some methods:

      OutPut:

    • #277746
      Participant
      Topics: 2
      Replies: 8
      Points: 30
      Rank: Member

      Thanks so much I believe with your help it’s working as expected.

Viewing 8 reply threads
  • You must be logged in to reply to this topic.