按文件中的列进行批处理排序 [英] Batch sort by column in file
本文介绍了按文件中的列进行批处理排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否可以按列对文本文件进行排序.例如
I wonder if there is any posibility to sort a text file by columns. For example
我有 aux1.txt
,其中包含这样的行
I have aux1.txt
with rows like this
Name SecondName Grade
在外壳中,我可以做到这一点
In shell i can do this
sort -r -k 3 aux1
它按第3列(等级)对文件进行排序.
It sorts the file by the 3rd column(grade).
批量
sort /+3 < aux1.txt
在第三个字母后对文件进行排序.
sorts the file after the 3rd letter.
我阅读了有关批次的排序手册,但没有结果.
I read the sort manual for batch but no results.
推荐答案
您可以使用批处理文件编写自己的 sort-wrapper .
You could write your own sort-wrapper with a batch file.
您只需要将列重新排序到一个临时文件中,
排序并重新订购.(几乎是显而易见的)
You only need to reorder the columns into a temporary file,
sort it and order it back. (nearly obvious)
REM *** Get the desired colum and place it as first column in the temporary file
setlocal DisableDelayedExpansion
(
for /F "tokens=1-3 delims= " %%A in (aux1.txt) DO (
set "par1=%%A"
set "par2=%%B"
set "par3=%%C"
setlocal EnableDelayedExpansion
echo(!par2! !par1! !par2! !par3!
endlocal
)
) > aux1.txt.tmp
REM ** Now sort the first colum, but echo only the rest of the line
for /F "usebackq tokens=1,* delims= " %%A in (`sort /r aux1.txt.tmp`) DO (
echo(%%B
)
这篇关于按文件中的列进行批处理排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文