SHELL1 统计文件的行数
cat nowcoder.txt | wc -l
SHELL2 打印文件的最后5行
tail -n 5 nowcoder.txt
SHELL3 输出7的倍数
seq 0 7 500
SHELL4 输出第5行的内容
sed -n '5p' nowcoder.txt
SHELL5 打印空行的行号
grep -nv '.' nowcoder.txt | cut -d ':' -f 1
SHELL6 去掉空行
grep '.' nowcoder.txt
SHELL7 打印字母数小于8的单词
for word in `cat nowcoder.txt`
do
if [ ${#word} -lt 8 ]; then
echo $word
fi
done
SHELL8 统计所有进程占用内存大小的和
total_mem=0
for mem in `awk '{print $6;}' nowcoder.txt`
do
total_mem=$[$total_mem + $mem]
done
echo $total_mem
SHELL9 统计每个单词出现的个数
awk '{ for (i = 1; i <= NF; i++) { print $i } }' nowcoder.txt | sort | uniq -c | sort -n | awk '{ print $2, $1 }'
SHELL10 第二列是否有重复
awk '{print $2}' nowcoder.txt | sort | uniq -cd | sort -n
SHELL11 转置文件的内容
num_columns=`head -n 1 nowcode