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,並打印該行,然後繼續。

在一些詳細的信息。附件







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