Bash编程实践

1.统计某工作目录及其子目录下的.c文件有多少行

#!/bin/bash

workspace=.
if [ "$#" -eq 1 ]
then
    $workspace=$1
fi

wc -l `find $workspace -name '*.c'` | tail -n -1 | cut -d " " -f 2

exit 0

2.统计某文件中出现最多10个单词的次数

#!/bin/bash

filename=$1

cat $filename | sort | uniq -c | sort -k1,1nr | head -10
8:30 -8:00, xz 9:00 10:30 [game p] , hh 7:30 9:00 [sport]
6 --> paper book
lt yxl
sz
mtlife chicken