需要在“a”上进行解释;查找“awk”;命令(Linux)
我正试图找出下面的命令需要在“a”上进行解释;查找“awk”;命令(Linux),linux,shell,awk,Linux,Shell,Awk,我正试图找出下面的命令 find ./ -type f | awk -F / -v OFS=/ '{$NF="";dir[$0]++} END {for (i in dir) print dir[i]i}' 输出如下所示: 6./Release_1_18_1_0_06_26/metadata/3_Control_Files/ 5./Release_1_18_1_0_06_26/metadata/7_SAS_Code/ 5./Release_1_18_1_0_06
find ./ -type f |
awk -F / -v OFS=/ '{$NF="";dir[$0]++} END {for (i in dir) print dir[i]i}'
输出如下所示:
6./Release_1_18_1_0_06_26/metadata/3_Control_Files/
5./Release_1_18_1_0_06_26/metadata/7_SAS_Code/
5./Release_1_18_1_0_06_26/others/1_content/
1./.cache/pip/selfcheck/
2./Release_1_18_1_0_06_26/metadata/5_Status/
1./Release_1_18_1_0_06_26/compute/2_packages/
1./sasuser.v94/
4./metadata/FR1_Release_1.17.1.1/3_Control_Files/
4./Release_1_18_1_0_06_26/metadata/6_Patches/
此命令用于计算当前路径中的输入代码数。但是,我不理解
{$NF=”“;dir[$0]+}END{for(I in dir)print dir[I]I}
,尤其是dir[$0]
。有人可以解释吗?请您在这里详细解释一下OP的代码
find ./ -type f | ##Running find command to find files in current directory and passing output as input to awk command.
awk -F / -v OFS=/ ' ##Running awk command setting field separator and output field separator as /
{
$NF="" ##Nullifying last field of current line here.
dir[$0]++ ##creating array dir with current line and keep increasing its value with one here.
}
END{ ##starting END block of this code here.
for(i in dir){ ##traversing through dir array here.
print dir[i]i ##printing index of dir array and it's index here.
}
}'
注意:
END
任何awk
代码块在最后读取输入文件时执行。请您在此处详细解释OP的代码
find ./ -type f | ##Running find command to find files in current directory and passing output as input to awk command.
awk -F / -v OFS=/ ' ##Running awk command setting field separator and output field separator as /
{
$NF="" ##Nullifying last field of current line here.
dir[$0]++ ##creating array dir with current line and keep increasing its value with one here.
}
END{ ##starting END block of this code here.
for(i in dir){ ##traversing through dir array here.
print dir[i]i ##printing index of dir array and it's index here.
}
}'
注意:
END
任何awk的块
在最后读取输入文件时执行。-F/
告诉awk用斜线分割行<代码>$0是整行代码
$NF=”“
将行中的最后一项(在本例中为文件名)替换为空白
然后,dir[$0]+
将整行(在文件名被删除后)作为索引放入哈希,并将该值递增1。有效地计算具有相同路径的项目数
END
块循环通过dir[]
散列中的所有键,首先打印计数,然后打印目录名。-F/
告诉awk按斜线拆分行<代码>$0是整行代码
$NF=”“
将行中的最后一项(在本例中为文件名)替换为空白
然后,dir[$0]+
将整行(在文件名被删除后)作为索引放入哈希,并将该值递增1。有效地计算具有相同路径的项目数
END
块循环遍历dir[]
散列中的所有键,首先打印计数,然后打印目录名。Nice。dir[$0]可以记住其行的最后一次计数,这就是数组可以增加值的原因。很好。dir[$0]可以记住其行的最后一次计数,这就是数组可以增加值的原因。