Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Good Evening,

I have been playing around with this for a while, I'm also somewhat new to Powershell, so a solid explanation would be appreciated.

I have to scrub text files for bad data which is formatted so that I could have the same number of digits in a number that I want to keep.

9192 (3spaces) 318 (4spaces) 416 (5spaces) 7768

I want to remove 9192 while preserving the spacing; I don't want to remove 7768. The numbers will not always be the same. I assumed I could use the spaces and the first number as a marker, but I'm having trouble just replacing the identified number while preserving the other number and the space. For example

ForEach-Object {$test -replace ".... (3spaces) ...", " "}

will identify the correct sequence, but I cant prevent replacing the entire string it seems. Any help is greatly appreciated. I feel like this shouldn't be that difficult ><.

share|improve this question
I have read your question three times and I still don’t understand it. Please edit the question to clarify what you mean –– what are you not saying (perhaps because you believe that it’s obvious)? (Don’t clarify your question in a comment.) – Scott Apr 19 '13 at 21:14
What is your criteria for whether or not you remove a sequence? – AthomSfere Apr 19 '13 at 21:23

You must log in to answer this question.

Browse other questions tagged .