简体   繁体   English

bash:首先对“查找”输出文件进行排序

[英]bash : sort “find” output files first

I'm trying to get a relative path's list of all my *.tex files to get a proper compilation list. 我试图获取所有* .tex文件的相对路径列表,以获取正确的编译列表。

I structured my directories the following way: each *.tex file containing other sections has an eponymous folder, which makes the structure looking this way : 我用以下方式构造目录:每个包含其他节的* .tex文件都有一个同名文件夹,这使结构看起来像这样:

./section1/ 
./section2/
./section1.tex
./section2.tex

Inside of each folder there is thus other *.tex files and eventually other directories in order for me to keep a clean hierarchy. 因此,在每个文件夹内有其他* .tex文件,最后还有其他目录,以便我保持干净的层次结构。

I'd like to get the following output and print it into a file (let's say "toc.txt') : 我想获取以下输出并将其打印到文件中(假设为“ toc.txt”):

./section1.tex

./section1/subsection1_1.tex
./section1/subsection1_2.tex
./section1/subsection1_3.tex


./section2.tex

./section2/subsection2_1.tex
./section2/subsection2_2.tex
./section2/subsection2_3.tex

I tried the following command : 我尝试了以下命令:

find . -name '*.tex' -print | sort

But it gives me the following result : 但这给了我以下结果:

./section1/subsection1_1.tex
./section1/subsection1_2.tex
./section1/subsection1_3.tex
./section1.tex
./section2/subsection2_1.tex
./section2/subsection2_2.tex
./section2/subsection2_3.tex
./section2.tex

I have to say I really don't want to struggle manually with reordering every line to get this toc file... 我不得不说我真的不想手动为每行重新排序以获取此toc文件...

Would you have an idea ? 你有个主意吗? :-) :-)

It has to do with collation order. 它与整理顺序有关。 This will work. 这将起作用。

find . -name '*.tex' -print | LC_COLLATE=C sort

And, just for fun, this is a bit crazy, but if you just replace your . 而且,只是为了好玩,这有点疯狂,但是如果您只是更换. with something that sorts higher up in the alphabet and is not found in your filenames, sort, then reverse the transform, it works. 用字母中较高的顺序排序,但在文件名中找不到的顺序排序,然后反转转换,即可正常工作。 eg 例如

find . -name '*.tex' -print | sed -e 's/\./aaaa/g' | sort | sed -e 's/aaaa/\./g'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM