#!/bin/bash
#展示文件夹下的文件前几行
dir=/tmp/data/hasbeeline.txt
#dir=/tmp/data/file.txt
for file in cat $dir
do
head -n 10 $file
#echo $file
替换第一行
sed -i ‘1c #!/bin/bash -x’ $file
将函数插入第一行
sed -i ‘1a function monitor_command_exec_issuccee(){\nif [ $? -ne 0 ]; then\n echo “fail”\n exit 1\nelse\n echo “success”\nfi\n}’ $file
#打印包含beeline的行
sed -n ‘/beeline/p’ $file
打印beeline所在的行
#echo $file
#sed -n ‘/beeline.*|[ ]*beeline/p’ $file
替换某一行
#sed -i ‘2c function monitor_command_exec_issuccee(){’ $file
sed在指定行下加
#sed -i ‘/beeline.*|[ ]*beeline/a monitor_command_exec_issuccee’ $file
#sed 查询文件中包含beeline 和包含monitor_command_exec_issuccee
echo $file
sed -n ‘/beeline.*|[ ]*beeline|monitor_command_exec_issuccee/p’ $file
done