locked
Get-Content result in Variable RRS feed

  • Question

  • Tower
    Hello, I have a stupid question, I have a file and in this one I search for a word, I want to put it in a variable and the distinguished. Example:
    
    Searched word: Tower
    
    The tower is far there, the tower is beautiful, the tower is beautiful, the tower is beautiful ...
    
    $ variable [0] = Tower
    $ variable [1] = Tower $ variable [2] = Tower $ variable [3] = Tower
    I was thinking of using a couplet to a pipeline but I'm a little lost ^^ thank you in advance to those who answer!

    • Edited by Warget Wednesday, March 7, 2018 1:04 PM
    Wednesday, March 7, 2018 1:02 PM

All replies

  • Hi,

    I don't know what you want to do exactly but this line should at least bring you closer to your solution. ;)

    [array]$var = ((Get-Content C:\temp\test_tower.txt).split(" ") -match "tower")

    If you enter $var[0..3] then you get the different "towers".

    • Edited by Paul Pi Wednesday, March 7, 2018 2:58 PM Had to remove a dot. :D
    • Proposed as answer by darklinkrising Wednesday, March 7, 2018 8:39 PM
    Wednesday, March 7, 2018 2:57 PM