I need to sort a filename pair sorted by time. Every file starts with AUSZUG or UMSATZ (and some numbers after). But the problem is that I cannot sort it by just time because some files can be uploaded (created) not as pair. For example, default sort:
我需要对按时间排序的文件名对进行排序。每个文件都以AUSZUG或UMSATZ(以及之后的一些数字)开头。但问题是我无法按时间排序,因为某些文件可以上传(创建)而不是成对。例如,默认排序:
ls -ltr --time-style "long-iso" {UMSATZ,AUSZUG}* | head -n 20
-rw-r--r-- 1 user group 0 2015-05-04 14:59 UMSATZ_2107381391.TXT.GPG
-rw-r--r-- 1 user group 0 2015-05-04 14:59 AUSZUG_2107381391.TXT.GPG
-rw-r--r-- 1 user group 0 2015-05-04 15:00 UMSATZ_1111111122.TXT.GPG
-rw-r--r-- 1 user group 0 2015-05-04 15:00 AUSZUG_1111111122.TXT.GPG
-rw-r--r-- 1 user group 0 2015-05-04 15:00 UMSATZ_9785745789.TXT.GPG
-rw-r--r-- 1 user group 0 2015-05-04 15:00 AUSZUG_9785745789.TXT.GPG
-rw-r--r-- 1 user group 0 2015-05-04 15:17 UMSATZ_6785745789.TXT.GPG
-rw-r--r-- 1 user group 0 2015-05-04 15:17 AUSZUG_6785745789.TXT.GPG
-rw-r--r-- 1 user group 0 2015-05-04 15:45 AUSZUG_8785745789.TXT.GPG
-rw-r--r-- 1 user group 0 2015-05-04 15:45 AUSZUG_5785745789.TXT.GPG
-rw-r--r-- 1 user group 0 2015-05-04 15:45 UMSATZ_8785745789.TXT.GPG
-rw-r--r-- 1 user group 0 2015-05-04 15:45 UMSATZ_5785745789.TXT.GPG
You can see, UMSATZ pair for AUSZUG_5785745789.TXT.GPG
are in last line
你可以看到,AUSZUG_5785745789.TXT.GPG的UMSATZ对在最后一行
I can solve this by sort
我可以通过排序解决这个问题
ls -ltr --time-style "long-iso" {UMSATZ,AUSZUG}* | sort -t "_" -k 2 | head -n 20
-rw-r--r-- 1 user group 0 2015-05-04 15:00 AUSZUG_1111111122.TXT.GPG
-rw-r--r-- 1 user group 0 2015-05-04 15:00 UMSATZ_1111111122.TXT.GPG
-rw-r--r-- 1 user group 0 2015-05-04 14:59 AUSZUG_2107381391.TXT.GPG
-rw-r--r-- 1 user group 0 2015-05-04 14:59 UMSATZ_2107381391.TXT.GPG
-rw-r--r-- 1 user group 0 2015-05-04 15:45 AUSZUG_5785745789.TXT.GPG
-rw-r--r-- 1 user group 0 2015-05-04 15:45 UMSATZ_5785745789.TXT.GPG
-rw-r--r-- 1 user group 0 2015-05-04 15:17 AUSZUG_6785745789.TXT.GPG
-rw-r--r-- 1 user group 0 2015-05-04 15:17 UMSATZ_6785745789.TXT.GPG
-rw-r--r-- 1 user group 0 2015-05-04 15:45 AUSZUG_8785745789.TXT.GPG
-rw-r--r-- 1 user group 0 2015-05-04 15:45 UMSATZ_8785745789.TXT.GPG
-rw-r--r-- 1 user group 0 2015-05-04 15:00 AUSZUG_9785745789.TXT.GPG
-rw-r--r-- 1 user group 0 2015-05-04 15:00 UMSATZ_9785745789.TXT.GPG
But now it's not by the time :( Anyone idea to sort it by AUSZUG-UMSATZ pair sorted by time?
但现在不是时候了:(任何人都想按AUSZUG-UMSATZ排序按时间排序?
2 个解决方案
#1
I'm not sure if I got you right, I understand that you want to have a list of UMSATZ_*
files sorted by time interlaced with the corresponding AUSZUG_*
files. You can get this in bash with this one-liner:
我不确定我是否帮助你,我知道你想要一个按时间排序的UMSATZ_ *文件列表与相应的AUSZUG_ *文件隔行扫描。你可以通过这个单行使用bash获得:
ls -t UMSATZ_* | while read x; do echo "$x"; echo "AUSZUG${x#UMSATZ}"; done
The unusually looking ${x#UMSATZ}
strips the string UMSATZ
from the front of the x
variable.
不寻常的$ {x#UMSATZ}从x变量的前面剥离字符串UMSATZ。
#2
Why not simply just find all of the UMSATZ*
files by time, and then list the AUSZUG*
one for each of the UMSATZ*
you find:
为什么不按时找到所有UMSATZ *文件,然后列出您找到的每个UMSATZ *的AUSZUG *:
ls -tr UMSATZ* | while read file
do
sans_prefix=${file#UMZATZ}
ls -ld *$sans_prefix
done
Or something like this... The ${file#UMSATZ}
removes the prefix UMSATZ
from $file
, so that if $file
equals UMSATZ_1111111122.TXT.GPG
, then $sans_prefix
equals _1111111122.TXT.GPG
. The *$sans_prefix
should list both files with the same numeric suffix.
或类似的东西...... $ {file#UMSATZ}从$ file中删除前缀UMSATZ,因此如果$ file等于UMSATZ_1111111122.TXT.GPG,则$ sans_prefix等于_1111111122.TXT.GPG。 * $ sans_prefix应列出具有相同数字后缀的两个文件。
#1
I'm not sure if I got you right, I understand that you want to have a list of UMSATZ_*
files sorted by time interlaced with the corresponding AUSZUG_*
files. You can get this in bash with this one-liner:
我不确定我是否帮助你,我知道你想要一个按时间排序的UMSATZ_ *文件列表与相应的AUSZUG_ *文件隔行扫描。你可以通过这个单行使用bash获得:
ls -t UMSATZ_* | while read x; do echo "$x"; echo "AUSZUG${x#UMSATZ}"; done
The unusually looking ${x#UMSATZ}
strips the string UMSATZ
from the front of the x
variable.
不寻常的$ {x#UMSATZ}从x变量的前面剥离字符串UMSATZ。
#2
Why not simply just find all of the UMSATZ*
files by time, and then list the AUSZUG*
one for each of the UMSATZ*
you find:
为什么不按时找到所有UMSATZ *文件,然后列出您找到的每个UMSATZ *的AUSZUG *:
ls -tr UMSATZ* | while read file
do
sans_prefix=${file#UMZATZ}
ls -ld *$sans_prefix
done
Or something like this... The ${file#UMSATZ}
removes the prefix UMSATZ
from $file
, so that if $file
equals UMSATZ_1111111122.TXT.GPG
, then $sans_prefix
equals _1111111122.TXT.GPG
. The *$sans_prefix
should list both files with the same numeric suffix.
或类似的东西...... $ {file#UMSATZ}从$ file中删除前缀UMSATZ,因此如果$ file等于UMSATZ_1111111122.TXT.GPG,则$ sans_prefix等于_1111111122.TXT.GPG。 * $ sans_prefix应列出具有相同数字后缀的两个文件。