You are not logged in.

#1 20 May 2019 17:12

kteague
Member
Registered: 07 May 2019
Posts: 14

Parse text file

Goal:
1. Parse a text file for text string: "Order No: Foo bar"
2. Strip "Order No: " out and leave me with "Foo bar" in a variable.

> $ON = (Get-Content -Path .\myfile.txt) -match "Order No: "
> Write-Output $ON
Order No: Foo bar

I've attempted to use $ON.IndexOf to separate it, based on this example I found:

$pos = $name.IndexOf(";")
$leftPart = $name.Substring(0, $pos)
$rightPart = $name.Substring($pos+1)

but I get an error:

Method invocation failed because [System.Object[]] doesn't contain a method named 'IndexOf'.

Offline

Board footer

Powered by