如何批量使用sort命令并通过/+ 9进行排序 [英] How to use sort command in batch and sort over /+9

查看:87
本文介绍了如何批量使用sort命令并通过/+ 9进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个学校项目,其中一个任务是编写一个批处理脚本,对文本文件中的列进行排序.

I´m working on a school project where one task is to write a batch script that sort columns from a text file.

示例文本文件:

078 Hyllplan    1200    100 30  2
077 Bokhylla    5000    120 30  80
096 Skap        15000   80  40  85
146 VitGarderob 9000    80  60  200
100 Bankskiva   3650    180 100 5
163 Skrivbord   25800   120 60  70
182 Pelarbord   1600    60  60  70

由于此问题,它可以很好地对前两个列进行排序,但对其他列则不能排序.我该如何排序,例如第三列(排序/+ 12)等等

Now to the problem, its works fine to sort the two first columns but not the others. How can I sort for example the third column(sort /+12)and so on

推荐答案

一个选项可能是在批处理文件中使用PowerShell.如果您使用的是受支持的Windows系统,则可以使用PowerShell.

One option might be to use PowerShell in a batch-file. If you are on a supported Windows system, PowerShell will be available.

这将产生严格"限制.带有TAB分隔符的CSV文件.微软的观点是严格".CSV文件是用引号引起来的.

This will produce a "strict" CSV file with TAB delimiters. Microsoft's view of a "strict" CSV file is that fields are quoted.

powershell -NoLogo -NoProfile -Command ^
    "Get-Content -Path .\so66227463-447901.txt |" ^
        "ConvertFrom-Csv -Delimiter "`t" -Header @('key','name','n1','n2','n3','n4') |" ^
        "Sort-Object {[int]$_.n1} |" ^
        "ConvertTo-Csv -NoTypeInformation -Delimiter "`t" |" ^
        "Select-Object -Skip 1 |" ^
        "Out-File -FilePath '.\sorted.txt' -Encoding ascii"

如果您想要未加引号的输出文件,则可以调查 https://stackoverflow.com/a/63462493/447901

If you want an unquoted output file, you might investigate https://stackoverflow.com/a/63462493/447901

这篇关于如何批量使用sort命令并通过/+ 9进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆