Andrew Lichtenberg
Andrew Lichtenberg

Reputation: 123

In the Powershell how can I extract 1000 characters before and after a found pattern

I have a large file (3mb) and I need to extract 1000 characters before and after a found pattern.

I am currently using Select-String -Pattern "695614" in the Power Shell but this is printing out the entire file, there are not line breaks in this file.

Any idea?

Upvotes: 0

Views: 45

Answers (1)

mjolinor
mjolinor

Reputation: 68341

I think this should handle that;

(get-content c:\somedir\somefile.txt -raw) -replace '.*(.{1000}695614.{1000}).*','$1'

Upvotes: 2

Related Questions