001、
(base) root@PC1:/home/test2# ls collective.txt (base) root@PC1:/home/test2# cat collective.txt ## 测试文件, 删除每个字符中/前的所有内容 test1/1.txt test1/2.txt test1/3.txt test2/1.csv test2/2.csv test2/3.csv test3/1.map test3/2.map test3/3.map ## 使用awk循环来实现 (base) root@PC1:/home/test2# awk '{for(i = 1; i <= NF; i++) {if($i ~ /\//) {sub(".*/", "", $i); printf("%s ", $i)} else {printf("%s ", $i)}} {printf("\n")}}' collective.txt 1.txt 2.txt 3.txt 1.csv 2.csv 3.csv 1.map 2.map 3.map