我有几个类型的文件:
id2018.12.15.log
id2018.12.16.log
id2018.12.17_a.log
id2018.12.17_b.log
...
我需要对这些文件名中的不同日期进行排序,并对后缀进行排序。
我知道我需要使用cut,sed,sort命令的组合。我也知道最好将输出存储在一个文件中,但它不一定是关键。有什么想法吗?
感谢。
答案 0 :(得分:-1)
If your files names are guaranteed to NOT contains space/newline:
$ ls -1
2018.12.18_z
id2018.12.15.log
id2018.12.16.log
id2018.12.17_a.log
id2018.12.17_b.log
$ printf '%s\n' * | grep -oP '\d{4}\.\d{2}\.\d{2}' | sort -u
2018.12.15
2018.12.16
2018.12.17
2018.12.18
$ printf '%s\n' * | grep -oP '\d{4}\.\d{2}\.\d{2}_\K\w+' | sort -u
a
b
z