统计文件得行数
题目描述:
写一个 bash脚本以输出一个文本文件 nowcoder.txt中的行数
cat nowcoder.txt | wc -l
打印文件的最后5行
题目描述:
经常查看日志的时候,会从文件的末尾往前查看,于是请你写一个 bash脚本以输出一个文本文件 nowcoder.txt中的最后5行
tail -n 5 nowcoder.txt
输出7的倍数
题目描述:
写一个 bash脚本以输出数字 0 到 500 中 7 的倍数(0 7 14 21…)的命令
#!/bin/bash
#输出数字 0 到 500 中 7 的倍数(0 7 14 21…)的命令
index=0
result={}
for (( i=0; i <= 500; i++ ))
do
if ((
i
t
h
e
n
r
e
s
u
l
t
[
i % 7 == 0)) then result[
ithenresult[index]=
i
i
n
d
e
x
=
i index=
iindex=index+1
fi
done
echo ${result[*]}
或者
seq 0 500 | awk ‘$0%7==0 {print $0}’
提取单词中的数字
例如
nowcoder.txt文件内容如下
a12b8
10ccc
2521abc
9asf
cat nowcoder.txt | tr -c [0-9] “\n” | sed ‘/^$/d’ | tr “\n” " "
输出:
12 8 10 2521 9
https://www.jb51.net/article/135168.htm