- <#*,:&cls
- @echo off
- cd /d "%~dp0"
- powershell -C "Set-Location -LiteralPath ([Environment]::CurrentDirectory);. ([ScriptBlock]::Create((Get-Content -LiteralPath \"%~f0\" -ReadCount 0 | Out-String)))"
- pause
- exit /b
- #>
-
- $arrFiles = "123.txt", "23.txt", "3000.txt"
- foreach ($itemFile in $arrFiles) {
- try {
- $basename = [system.io.path]::GetFileNameWithoutExtension($itemFile)
- $ext = [System.IO.Path]::GetExtension($itemFile)
- $psoList = (Get-Content -ReadCount 0 -LiteralPath $itemFile -ErrorAction Stop) | Select-Object -Property @{
- Name = 'Line'
- Expression = { $_ }
- }, @{
- Name = 'Field2'
- Expression = { ($_ -split '_')[1] }
- }
- $psoList | Sort-Object -Property @{
- Expression = {
- $_.Field2.Length
- }
- Ascending = $true
- }, @{
- Expression = {
- $_.Field2
- }
- Ascending = $false
- } | Select-Object -ExpandProperty Line | Set-Content -LiteralPath "${basename}-1${ext}"
- $psoList | Sort-Object -Property @{
- Expression = {
- $_.Field2.Length
- }
- Ascending = $false
- }, @{
- Expression = {
- $_.Field2
- }
- Ascending = $true
- } | Select-Object -ExpandProperty Line | Set-Content -LiteralPath "${basename}-a${ext}"
- $psoList | Sort-Object -Property @{
- Expression = {
- $_.Field2.Length
- }
- Ascending = $false
- }, @{
- Expression = {
- $_.Field2
- }
- Ascending = $false
- } | Select-Object -ExpandProperty Line | Set-Content -LiteralPath "${basename}-z${ext}"
-
- } catch {}
- }
复制代码
|