I have a test script as follows:
# listingParser.ps1 --- by alphabetical order NOT numeric
$input_path = "C:\test\test3\Copy of 31832_226140__0001-00010.txt"
$output_file = "C:\test\test3\filterorder.txt"
$regexNum = '\d\d\d\s[A-Z][A-Z][A-Z]' # Roll Entry Number and NAME
$result = select-string -Path $input_path -Pattern $regexNum -CaseSensitive | % {
$_.Matches } | % { $_.Value }
$result | Sort-Object > $output_file
The output looks like this:
001 BUZ
001 CAR
002 BUZ
003 BYE
005 BYE
007 CAR
008 BYF
009 BYF
010 CAR
011 BYG
012 CAR
014 CAR
017 BYT
018 BYT
021 CAD
The issues are:
My search returns only one instance per line of text. Some lines of the text file contain multiple examples, of the search pattern, some not. Well at least that is my interpretation of the result (I have just checked this again to be sure) How do I specify ALL examples on any line of the file?
My requirement is to sort the
[A-Z][A-Z][A-Z]part of the regex. Taking into account the original search requires the numerical part of the string.
For issue#2: This PowerShell: How do I sort a text file by column? describes splitting each string, casting before sorting. I incorporated this but got errors. In the end I simplified it (removing the cast & sort direction) and got it working.
$result | Sort-Object { $_.split()[-1] } > $output_file
So I think I have issue#2 sorted.
001 BUZ
002 BUZ
003 BYE
005 BYE
008 BYF
009 BYF
011 BYG
017 BYT
018 BYT
021 CAD
031 CAI
030 CAI
029 CAI
032 CAI
024 CAI
So that just leaves how to return all examples of my search.
Any suggestions would be appreciated.