2

How do I continue to get the 12345 as output?

file.txt

MyText: 12345

myscript

Get-Content file.txt | Select-String "MyText:" | Select-Object Line

Now I would like to save last five characters, how to I retreive them?

1 Answer 1

1

The Select-String cmdlet -Pattern parameter expects a regex - so you can get your desired output by capturing the five digits. Note that the Select-String cmdlet also takes a -Path parameter to retrieve the content of a file. This means you can omit the first Get-Content command:

(Select-String -Path .\file.txt -Pattern 'MyText: (\d{5})').Matches.Groups[1].Value
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.