题目要求
在文本文档1.txt第5行(假设文件行数大于5)后面增加如下内容:
# This is a test file.
# Test insert line into this file.
参考答案
#!/bin/bash
#这个脚本用来给文件增加行
#作者:猿课-阿铭 www.apelearn.com
#日期:2018-11-01
n=0
cat 1.txt |while read line
do
n=$[$n+1]
if [ $n -eq 5 ]
then
echo $line
echo -e "# This is a test file.\n# Test insert line into this file."
else
echo $line
fi
done
题目要求
设计一个shell程序,在每月第一天备份并压缩/etc目录的所有内容,存放在/root/bak目录里,且文件名为如下形式"yymmdd_etc.tar.gz",yy为年,mm为月,dd为日。
参考答案
#!/bin/bash
#这个脚本用来备份/etc/目录
#作者:猿课-阿铭 www.apelearn.com
#日期:2018-12-02
d1=`date +%d`
d2=`date +%y%m%d`
if [ $d1 == "01" ]
then
cd /etc/
tar czf /root/bak/$d2_etc.tar.gz ./
fi
题目要求
将文件内所有的单词的重复次数计算出来,只需要列出重复次数最多的10个单词。
参考答案
#!/bin/bash
#这个脚本用来找出重复的单词
#作者:猿课-阿铭 www.apelearn.com
#日期:2018-12-02
for w in `sed 's/[^a-zA-Z]/ /g' $1`
do
echo $w
done |sort |uniq -c |sort -nr|head
题目要求
需