用shell从文件中提取指定字符串的行

来源:互联网 发布:mac虚拟机配置文件 编辑:程序博客网 时间:2024/05/16 17:55

#保存为.sh文件

#!/bin/bash 



IFS="
"
while read -r line 
do
   if [ "DROP TABLE" = ${line:0:10} ];
   then
         echo $line >>/home/test//test2.sql
   fi

done <./1.sql



#删除1.sql中含有指定字符串DROP TABLE的行,并将结果输出到2.sql
sed -e "/DROP TABLE/d" 1.sql >./2.sql

0 0
原创粉丝点击