巴什排序正则表达式 [英] Bash sort by regexp
本文介绍了巴什排序正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些关于100与下面的语法文件
I have something about 100 files with the following syntax
ahfsdjfhdfhj_EPI_34_fdsafasdf
asdfasdf_EPI_2_fdsf
hfdjh_EPI_8_dhfffffffffff
ffffffffffasdfsdf_EPI_1_fyyy44
...
有总是EPI_NUMBER。我怎样才能通过这个号码排序呢?
There is always EPI_NUMBER. How can I sort it by this number?
推荐答案
从你的例子看来,分隔符是 _
和文字 EPI_nnn
来在相同的位置后,分隔符 _
。如果总是这样的,那么你可以使用以下命令将文件进行排序:
From your example it appears that delimiter is _
and text EPI_nnn
comes at the same position after delimiter _
. If that is always the case then you can use following command to sort the file:
sort -n -t "_" -k 3 file.txt
更新:
如果的位置EPI _
文本不是的固定的再使用下面的shell命令:
If position of EPI_
text is not fixed then use following shell command:
sed 's/^\(.*EPI_\)\(.*\)$/\2##\1/' file.txt | sort -n -t "_" -k1 | sed 's/^\(.*\)##\(.*\)$/\2\1/'
这篇关于巴什排序正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文