Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于查找具有相似名称的文件的Shell脚本_Shell - Fatal编程技术网

用于查找具有相似名称的文件的Shell脚本

用于查找具有相似名称的文件的Shell脚本,shell,Shell,我有一个包含多个文件的目录,格式如下: file001_a file002_a file002_b file003_a 使用shell脚本,我想知道最简单的方法是列出该目录中前7个字母中有重复项的所有文件;即上述输出为: file002_a file002_b 任何帮助都将不胜感激 它伤害了我的眼睛,但却做了我想做的一切——谢谢你!) ls -1 *_*| awk '{fn=substr($0,1,7);a[fn]=a[fn]" "substr($0,8)}END{for(i in a) p

我有一个包含多个文件的目录,格式如下:

file001_a
file002_a
file002_b
file003_a
使用shell脚本,我想知道最简单的方法是列出该目录中前7个字母中有重复项的所有文件;即上述输出为:

file002_a
file002_b

任何帮助都将不胜感激

它伤害了我的眼睛,但却做了我想做的一切——谢谢你!)
ls -1 *_*| awk '{fn=substr($0,1,7);a[fn]=a[fn]" "substr($0,8)}END{for(i in a) print i,a[i]}'