【发布时间】:2018-08-17 22:17:36
【问题描述】:
我有这个:
D-T4-0.txt
A-2.txt
C-3-1.txt
B-X1-3.txt
E-2-4.txt
我希望订购如下:
D, C, A, B, E
我需要查看每个(.txt 之前)D-0, C-1, A-2, B-3, E-4 中的最后一个数字。
有可能吗?
【问题讨论】:
标签: sorting unix terminal find
我有这个:
D-T4-0.txt
A-2.txt
C-3-1.txt
B-X1-3.txt
E-2-4.txt
我希望订购如下:
D, C, A, B, E
我需要查看每个(.txt 之前)D-0, C-1, A-2, B-3, E-4 中的最后一个数字。
有可能吗?
【问题讨论】:
标签: sorting unix terminal find
for i in `awk -F- '{print $NF}' file_name |sort`;do grep -- -$i file_name;done
【讨论】:
do 后面有一个错误的分号:)
ls |awk -F- '{print $NF}'|sort;do ls |grep -- -$i ;done
您可以在这样的管道中执行此操作:
# List files
ls |
# Include the sorting key in the front as well
sed -E 's/^(.*)([0-9]+)\.txt$/\2\t\1\2.txt/' |
# Sort on the sorting key
sort -n |
# Remove the sorting key
cut -f2-
# Grab the first letter
cut -c1
输出:
D
C
A
B
E
【讨论】: