shell 统计当前目录下文件个数,使用管道组合命令: ls -1 | wc -l 解释: ls -1 表示一行一个列出文件名. wc -l 表示打印统计的行数. 两个命令通过管道连在一起表示打印列出的文件名的总行数. 参考链接:Counting Files in the Current Directory…
Ubuntu14.04 给定一个文本,统计其中单词出现的次数 方法1 # solution 1 grep与awk配合使用,写成一个sh脚本 fre.sh sh fre.sh wordfretest.txt #! /bin/bash# solution 1 ] then echo "Usage:$0 args error" exit fi ] then echo "analyse the first file $1" fi #get the first file fi…
一行搞定-统计一句话中每个单词出现的个数 >>> s'i am a boy a bood boy a bad boy' 方式一:>>> dict([(i,s.split().count(i)) for i in s.split()]){'a': 3, 'boy': 3, 'i': 1, 'am': 1, 'bad': 1, 'bood': 1} >>> set([(i,s.split().count(i)) for i in s.split()])se…