Linux 文件处理每隔特定行数增加字符串

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/moscot_wu/article/details/89154579

在使用SQL生成脚本时,许多工具能够提供多少行进行提交的功能。例如100行提交一次。

如果需要自己对生成的文件手工加入commit动作,该如何去实现。

个人想到两种方法,一是借助游标,每100行打印一个commit;

第二种就是对生成的文件进行处理,每隔特定行数插入一个commit动作;

#!/bin/sh
#This a process add commit to the script
#create by Mascot in April 9 2019 

FN=Test.sql
cat $FN|awk 'NR%100==0{print NR}'|while read line
do 
echo "$line"
sed -i ''$line'a commit;' $FN
done

FN 是你的文件名

NR%/100 中100即你要每隔多少行插入

commit 为你想要插入的字符串。

可以做成参数形式。

猜你喜欢

转载自blog.csdn.net/moscot_wu/article/details/89154579