Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
1  
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
1  
What is your criteria for whether or not you remove a sequence? –  AthomSfere Apr 19 '13 at 21:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.