Mar*_*era 7 unix bash awk sed wc
这是我尝试做到的
*.java文件find . -name '*.java'wc -lsed '$d'wc输出中的最大行数awk 'max=="" || data=="" || $1 > max {max=$1 ; data=$2} END{ print max " " data}' 然后将其合并为单行
find . -name '*.java' | xargs wc -l | sed '$d' | awk 'max=="" || data=="" || $1 > max {max=$1 ; data=$2} END{ print max " " data}'
Run Code Online (Sandbox Code Playgroud)
我可以以某种方式实现只计算非空行?
Sha*_*hin 16
find . -type f -name "*.java" -exec grep -H -c '[^[:space:]]' {} \; | \
sort -nr -t":" -k2 | awk -F: '{print $1; exit;}'
Run Code Online (Sandbox Code Playgroud)
如果您还想查看非空行数,请替换该awk命令head -n1.
命令细分:
find . -type f -name "*.java" -exec grep -H -c '[^[:space:]]' {} \;
'---------------------------' '-----------------------'
| |
for each *.java file Use grep to count non-empty lines
-H includes filenames in the output
(output = ./full/path/to/file.java:count)
| sort -nr -t":" -k2 | awk -F: '{print $1; exit;}'
'----------------' '-------------------------'
| |
Sort the output in Print filename of the first entry (largest count)
reverse order using the then exit immediately
second column (count)
Run Code Online (Sandbox Code Playgroud)
find . -name "*.java" -type f | xargs wc -l | sort -rn | grep -v ' total$' | head -1
Run Code Online (Sandbox Code Playgroud)