昨天朋友問我sqlserver轉mysql雜麼弄,我說百度呀,結果百度一頓還是有些問題 最後寫了個指令碼轉換一下 順便自己也學習一下shell指令碼
筆記先貼這裡 後續整理一下
USE [huaxindev]GO/****** Object: Table [dbo].[JCRttt] Script Date: 06/06/2013 18:14:22 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOSET ANSI_PADDING ONGO CREATE TABLECREATE TABLE [dbo].[JCRttt]([RtyID] [varchar](20) NOT NULL,[CaseNo] [varchar](20) NULL,[RiskReCode] [char](10) NULL,[Money] [numeric](16, 2) NULL, CONSTRAINT [PK_JCRESPONBILITY] PRIMARY KEY NONCLUSTERED ([ResponsibilityID] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]GOSET ANSI_PADDING OFFGO/****** Object: Table [dbo].[JCReee] Script Date: 06/06/2013 18:14:22 ******/
指令碼如下
#!/bin/bashPROJECT_NAME=$1NAME0="\/\*\*\*\*\*\*"NAME3='CREATE TABLE 'NAME1='CONSTRAINT'NAME2='\*\*\*\*\*\*\/'NAME4="print 'Processed"NAME5="INSERT"NAME5="INSERT"sed -i 's/\[dbo\].//g' $1sed -i 's/\[//g' $1sed -i 's/\]//g' $1echo *********快樂的分割線1*********beg=0end=0lastValue=0index=0value1=`grep "$NAME4" -n $1 | cut -d ":" -f1 | head -50000`echo value1=$value1for i in $value1do index=$(($index+1)) beg=$(($i-1-$lastValue)) #echo 開始:$beg end=$(($beg+1)) #echo 結束:$end lastValue=$(($lastValue+$end-$beg+1)) #echo lastValue=$lastValue echo begin:$index 開始:$beg 結束:$end b=$(($beg)) e=$(($end)) sed -n "$b p" $1 sed -n "$e p" $1 sed -i "${beg},${end}d" $1 doneecho *********快樂的分割線2*********beg=0end=0lastValue=0index=0value1=`grep "$NAME0" -n $1 | cut -d ":" -f1 | head -50000`echo value1=$value1value2=`grep "$NAME3" -n $1 | cut -d ":" -f1 | head -50000`echo value2=$value2for i in $value1do index=$(($index+1)) beg=$(($i+1-$lastValue)) #echo 開始:$beg for j in $value2 do if [ $j -gt $i ]; then end=$j break; fi done end=$(($end-1-$lastValue)) #echo 結束:$end lastValue=$(($lastValue+$end-$beg+1)) #echo lastValue=$lastValue echo begin:$index 開始:$beg 結束:$end b=$(($beg-1)) e=$(($end+1)) sed -n "$b p" $1 sed -n "$e p" $1 #echo end:$index if [ $end -le $beg ]; then echo xxxxxxxxxxxxxxxxxxxxxx wrong msg xxxxxxxxxxxx echo 開始:$beg echo 結束:$end echo testssslastValue=$lastValue fi sed -i "${beg},${end}d" $1donesed -i 's/\/\*\*\*\*\*\*/INSERT_FUCK\/\*\*\*\*\*\*/g' $1echo *********快樂的分割線3*********beg=0end=0lastValue=0index=0value1=`grep "$NAME1" -n $1 | cut -d ":" -f1 | head -50000`echo value1=$value1value2=`grep "$NAME5" -n $1 | cut -d ":" -f1 | head -50000`echo value2=$value2for i in $value1do index=$(($index+1)) beg=$(($i-$lastValue)) #echo 開始:$beg for j in $value2 do if [ $j -gt $i ]; then end=$j break; fi done end=$(($end-1-$lastValue)) #echo 結束:$end lastValue=$(($lastValue+$end-$beg+1)) #echo lastValue=$lastValue echo begin:$index 開始:$beg 結束:$end b=$(($beg)) e=$(($end)) sed -n "$b p" $1 sed -n "$e p" $1 #echo end:$index if [ $end -le $beg ]; then echo xxxxxxxxxxxxxxxxxxxxxx wrong msg xxxxxxxxxxxx echo 開始:$beg echo 結束:$end echo testssslastValue=$lastValue fi sed -i "${beg},${end}d" $1doneecho *********快樂的分割線4*********sed -i 's/INSERT/;INSERT/g' $1sed -i 's/\/\*\*\*\*\*\*/;\/\*\*\*\*\*\*/g' $1sed -i 's/INSERT_FUCK;//g' $1echo *********我日還有2種手動替換吧 麻煩死了*********