按文件列按批次排序
问题描述:
我想知道是否有任何可能性按列排序文本文件。例如按文件列按批次排序
我aux1.txt
像这样
Name SecondName Grade
排在外壳我能做到这一点
sort -r -k 3 aux1
它排序由第3列(级)的文件。
在批处理
sort /+3 < aux1.txt
排序第三个字母后的文件。
我阅读了批次的排序手册,但没有结果。
答
您可以使用批处理文件编写自己的整理包装。
您只需将列重新排序到临时文件中,
对其进行排序并重新排序。 (将近明显)
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
)
答
对你来说可能已经太晚了,但作为一般建议,你可以做得比创建一个临时文件简单得多。只要管这一切通过排序:
for /f "tokens=1-3" %%a in ('(for /f "tokens=1-3" %%x in (aux1.txt^) do @echo %%z %%x %%y^)^|sort') do echo %%b %%c %%a
请注意,这是一个简单的命令,并且可以通过在命令提示符下没有在所有任何批处理文件打字只是用(必须减少%%的对,当然)。
谢谢,它的作品! – vladCovaliov 2012-04-16 13:20:10