1

Ok I have a portion of a script that looks like this.

Switch(GCI $source\*.EDIPROD){
    {(GC $_|Select -first 1).substring(176) -match "^834"}{$_ | ?{$_.Name -match "^.+?\.D(\d{6}).*"} | Rename-Item -NewName {"834Dailyin$($Matches[1]).txt"};Continue}
    {(GC $_|Select -first 1).substring(405) -match "^030"}{$_ | ?{$_.Name -match "^.+?\.D(\d{6}).*"} | Rename-Item -NewName {"834Roster$($Matches[1]).txt"};Continue}
    {(GC $_|Select -first 1).substring(176) -match "^820"}{$_ | ?{$_.Name -match "^.+?\.D(\d{6}).*"} | Rename-Item -NewName {"820Dailyin$($Matches[1]).txt"};Continue}
    {(GC $_|Select -first 1) -match "NO INPUT"}{$_ | ?{$_.Name -match "^.+?\.D(\d{6}).*"} | Rename-Item -NewName {"NOINPUTin$($Matches[1]).txt"};Continue}
    {(GC $_|Select -first 1) -match ""}{$_ | ?{$_.Name -match "^.+?\.D(\d{6}).*"} | Rename-Item -NewName Default {"Could not find 834 or 820 qualifier in file $_"};Continue}
}

My question comes into play on the first and second criteria.

So it's not looking for the same sub-string value, if a file comes in and has an 834 at substring 176, is it going to get matched before it checks for a ^030 at column 405?

I think it will evaluate the 176 column first, so maybe I should do two matches in the second one? or Move the second one to the first? What do you guys think?

1 Answer 1

1

Yes it will match on 834 first because that is the first switch condition. Also, since you are using continue, after the 834 match, the switch statement will not process any more conditions for the current file and move to the next file in the input. So if you want to match multiple conditions on a single file, don't use continue. And if you need to match 030 first, then move that condition up so it's the first condition.

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.