sed

sed '/WHERE/{:a;N;/SET/!ba;s/\([^\n]*\)\n\(.*\)\n\(.*\)/\3\n\2\n\1/}' 1.txt

| sed -r '/WHERE/{:a;N;/@4/!ba;s/###   @2.*//g}'

| sed 's/### //g;s/\/\*.*/,/g'

| sed '/WHERE/{:a;N;/@1/!ba;s/,/;/g};s/#.*//g;s/COMMIT,//g'

| sed '/^$/d' > ./recover.sql

这个命令是看http://hcymysql.blog.51cto.com/5223301/1070148

在这里复习一下里面的一些sed的用法

在 sed 里也是可以实现循环跳转等功能的,这里会涉及到 3 个符号:冒号(:),b 命令,t 命令

man sed 里面的

: label

 Label for b and t commands.

}      The closing bracket of a { } block.上面黑色{}

{      Begin a block of commands (end with a }).

b label

Branch to label; if label is omitted, branch to end of script.

t label

If a s/// has done a  successful  substitution  since  the  last

input  line  was  read  and  since the last t or T command, then

branch to label; if label is omitted, branch to end of script.

n N    Read/append the next line of input into the pattern space.

下面是一个例子不难,理解原文http://www.groad.net/bbs/read.php?tid-6845.html

#echo "beyeb"| sed 's/^\(.\)\(.*\)\1/\2/;s/y/X/'

#eXe

继续

sed's/^\(.\)\(.*\)\1/\2/; b labletwo; :lableone s/y/X/; :labletwo s/y/Z/' beyeb.txt

#eZe

sed's/^\(.\)\(.*\)\1/\2/; b lableone; :lableones/y/X/; :labletwo s/y/Z/' beyeb.txt

#eXe

n和N的效果,文件

beyeb

beyeb

bayeb

beyeb

beyeb

[root@local_db ~]# sed '/ba/n;s/e/A/' 123.txt

bAyeb

bAyeb

bayeb

bAyeb

bAyeb

[root@local_db ~]# sed '/ba/N;s/e/A/' 123.txt

bAyeb

bAyeb

bayAb##继续后面的匹配

beyeb##跳过这一行了

bAyeb

n不操作匹配的行,而N不操作匹配的行的下一行,但是还会继续此行的接下来的替换(不知道我这么说对么)

sed '/test/{ n; s/aa/bb/; }' example-----如果test被匹配,则移动到匹配行的下一行,替换这一行的aa,变为bb,并打印该行,然后继续。

在一些详细的信息。附件







發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章