Reading a text file in PowerShell after of a marker

1k views Asked by At

I'm just wondering if it's possible to read the content of text file with specific index?

What I mean is like this, for example:

I have text file like this, 'test1.txt'

12345678900 ## ## readthistext

54321123440 ## ## hellothistext

I just want to read the content of text file after of the hashtag.

1

There are 1 answers

9
Ansgar Wiechers On BEST ANSWER

To read the text after the # characters you must read the file content up to the # characters first. Also, in PowerShell you normally read files either line by line (via Get-Content) or completely (via Get-Content -Raw). You can discard those parts of the read content that don't interest you, though. For instance:

(Get-Content 'C:\input.txt') -replace '^.*#'

The above will read the file C:\input.txt and for each line remove the text from the beginning of the line up to the last # character.