2
sed在短線路上工作正常,但不是長線路。使用下面的命令:如果線路很長,sed無法進行替換
sed 's/DEFINER=\`[a-z]*\`@\`localhost\`//g' temp.sql
當temp.sql包含短線這樣它的工作原理:
CREATE ALGORITHM=UNDEFINED DEFINER=`factstvdus`@`localhost` SQL SECURITY DEFINER VIEW `caseinfo` AS select `files`.`fileNumber` AS `fileNumber`...
然而,很長的線替換不會發生。我的目標是要刪除的每個實例:
DEFINER=`factstvdus`@`localhost`
的用戶名(在這種情況下factstvdus)並不總是相同的。 mysqldump在一條長線上輸出視圖定義,因此將它們包裝成我所知道的多條線並不容易。
我該如何獲得sed來處理長行或者是否有另一個我應該使用的工具?
更新:這是在CentOS 6,GNU的sed版本4.2.1
失敗的行完全和上面一樣,只是很長:
CREATE ALGORITHM=UNDEFINED DEFINER=`factstvdus`@`localhost` SQL SECURITY DEFINER VIEW `caseinfo` AS select `files`.`fileNumber` AS `fileNumber`,`files`.`fileTitle` AS `fileTitle`,`files`.`openDate` AS `openDate`,`files`.`applicantID` AS `applicantID`,`files`.`adjusterID` AS `adjusterID`,`files`.`adjusterType` AS `adjusterType`,`files`.`employerID` AS `employerID`,`files`.`insurerID` AS `insurerID`,`files`.`TPAid` AS `TPAid`,`files`.`employerContact` AS `employerContact`,`files`.`insurerContact` AS `insurerContact`,`files`.`TPAcontact` AS `TPAcontact`,`files`.`claimNumber` AS `claimNumber`,`files`.`AAid` AS `AAid`,`files`.`AAfirmID` AS `AAfirmID`,`files`.`GLDAid` AS `GLDAid`,`files`.`coverages` AS `coverages`,`files`.`policyNumber` AS `policyNumber`,`files`.`policyLimits` AS `policyLimits`,`files`.`DOH` AS `DOH`,`files`.`courtLocationID` AS `courtLocationID`,`files`.`NORfiled` AS `NORfiled`,`files`.`baseRate` AS `baseRate`,`files`.`recommendations` AS `recommendations`,`files`.`GAICID` AS `GAICID`,`files`.`fileStatus` AS `fileStatus`,`files`.`lastEventDate` AS `lastEventDate`,`files`.`flatFee` AS `flatFee`,`adjusters`.`adjusterFirstName` AS `adjusterFirstName`,`adjusters`.`adjusterMiddleName` AS `adjusterMiddleName`,`adjusters`.`adjusterLastName` AS `adjusterLastName`,`adjusters`.`adjusterOfficePhone` AS `adjusterOfficePhone`,`adjusters`.`adjusterCellPhone` AS `adjusterCellPhone`,`adjusters`.`adjusterFax` AS `adjusterFax`,`adjusters`.`adjusterPhoneExtension` AS `adjusterPhoneExtension`,`adjusters`.`adjusterEmail` AS `adjusterEmail`,`ADJ`.`companyID` AS `clientID`,concat(if((`ADJ`.`companyID` < 1000),_utf8'0',_utf8''),if((`ADJ`.`companyID` < 100),_utf8'0',_utf8''),if((`ADJ`.`companyID` < 10),_utf8'0',_utf8''),`ADJ`.`companyID`,_utf8'-',`files`.`fileNumber`) AS `fullFileNumber`,`ADJ`.`companyName` AS `clientName`,`ADJ`.`companyNameShort` AS `clientNameShort`,`ADJ`.`officePhone` AS `clientOfficePhone`,`ADJ`.`tollFreePhone` AS `clientTollFreePhone`,`EMP`.`companyName` AS `employerName`,`INSUR`.`companyName` AS `insurerName`,`TPA`.`companyName` AS `TPAname`,`AA`.`lawyerFirstName` AS `AAfirstName`,`AA`.`lawyerMiddleName` AS `AAmiddleName`,`AA`.`lawyerLastName` AS `AAlastName`,`AA`.`lawyerReceptionist` AS `AAreceptionist`,`AA`.`lawyerNotes` AS `AAnotes`,`AA`.`lawyerOfficePhone` AS `AAofficePhone`,`AA`.`lawyerCellPhone` AS `AAcellPhone`,`AA`.`lawyerFax` AS `AAfax`,`AA`.`lawyerEmail` AS `AAemail`,`AAF`.`officePhone` AS `AAfirmOfficePhone`,`AAF`.`tollFreePhone` AS `AAfirmTollFreePhone`,`AAF`.`faxNumber` AS `AAfirmFax`,`AAF`.`EAMSno` AS `AAfirmEAMSno`,`AAF`.`EAMSname` AS `AAfirmEAMSname`,`AA`.`lawyerPhoneExtension` AS `AAphoneExtension`,`AAF`.`firmName` AS `AAfirmName`,`GLDA`.`lawyerFirstName` AS `GLDAfirstName`,`GLDA`.`lawyerMiddleName` AS `GLDAmiddleName`,`GLDA`.`lawyerLastName` AS `GLDAlastName`,`GLDA`.`lawyerOfficePhone` AS `GLDAofficePhone`,`GLDA`.`lawyerCellPhone` AS `GLDAcellPhone`,`GLDA`.`lawyerFax` AS `GLDAfax`,`GLDA`.`lawyerEmail` AS `GLDAemail`,`GLDA`.`userID` AS `GLDAUserID`,`applicants`.`applicantFirstName` AS `applicantFirstName`,`applicants`.`applicantMiddleName` AS `applicantMiddleName`,`applicants`.`applicantLastName` AS `applicantLastName`,`applicants`.`applicantDOB` AS `applicantDOB`,`applicants`.`applicantSSN` AS `applicantSSN`,`applicants`.`applicantJobTitle` AS `applicantJobTitle`,`applicants`.`homePhone` AS `applicantHomePhone`,`applicants`.`cellPhone` AS `applicantCellPhone`,`applicants`.`applicantEmail` AS `applicantEmail`,`APPPHYSLOC`.`locationID` AS `applicantPhysicalLocationID`,`APPPHYSLOC`.`locationAddress` AS `applicantPhysicalAddress`,`APPPHYSLOC`.`locationCity` AS `applicantPhysicalCity`,`APPPHYSLOC`.`locationState` AS `applicantPhysicalState`,`APPPHYSLOC`.`locationZipCode` AS `applicantPhysicalZip`,`APPMAILLOC`.`locationID` AS `applicantMailLocationID`,`APPMAILLOC`.`locationAddress` AS `applicantMailAddress`,`APPMAILLOC`.`locationCity` AS `applicantMailCity`,`APPMAILLOC`.`locationState` AS `applicantMailState`,`APPMAILLOC`.`locationZipCode` AS `applicantMailZip`,`AAPHYSLOC`.`locationID` AS `AAphysicalLocationID`,`AAPHYSLOC`.`locationAddress` AS `AAphysicalAddress`,`AAPHYSLOC`.`locationCity` AS `AAphysicalCity`,`AAPHYSLOC`.`locationState` AS `AAphysicalState`,`AAPHYSLOC`.`locationZipCode` AS `AAphysicalZip`,`AAMAILLOC`.`locationID` AS `AAmailLocationID`,`AAMAILLOC`.`locationAddress` AS `AAmailAddress`,`AAMAILLOC`.`locationCity` AS `AAmailCity`,`AAMAILLOC`.`locationState` AS `AAmailState`,`AAMAILLOC`.`locationZipCode` AS `AAmailZip`,`AAFPL`.`locationID` AS `AAfirmPhysicalLocationID`,`AAFPL`.`locationAddress` AS `AAfirmPhysicalAddress`,`AAFPL`.`locationCity` AS `AAfirmPhysicalCity`,`AAFPL`.`locationState` AS `AAfirmPhysicalState`,`AAFPL`.`locationZipCode` AS `AAfirmPhysicalZip`,`AAFML`.`locationID` AS `AAfirmMailLocationID`,`AAFML`.`locationAddress` AS `AAfirmMailAddress`,`AAFML`.`locationCity` AS `AAfirmMailCity`,`AAFML`.`locationState` AS `AAfirmMailState`,`AAFML`.`locationZipCode` AS `AAfirmMailZip`,`ADJPHYSLOC`.`locationID` AS `adjusterPhysicalLocationID`,`ADJPHYSLOC`.`locationAddress` AS `adjusterPhysicalAddress`,`ADJPHYSLOC`.`locationCity` AS `adjusterPhysicalCity`,`ADJPHYSLOC`.`locationState` AS `adjusterPhysicalState`,`ADJPHYSLOC`.`locationZipCode` AS `adjusterPhysicalZip`,`ADJMAILLOC`.`locationID` AS `adjusterMailLocationID`,`ADJMAILLOC`.`locationAddress` AS `adjusterMailAddress`,`ADJMAILLOC`.`locationCity` AS `adjusterMailCity`,`ADJMAILLOC`.`locationState` AS `adjusterMailState`,`ADJMAILLOC`.`locationZipCode` AS `adjusterMailZip`,`ADJBILLLOC`.`locationID` AS `adjusterBillLocationID`,`ADJBILLLOC`.`locationAddress` AS `adjusterBillAddress`,`ADJBILLLOC`.`locationCity` AS `adjusterBillCity`,`ADJBILLLOC`.`locationState` AS `adjusterBillState`,`ADJBILLLOC`.`locationZipCode` AS `adjusterBillZip`,`EMPPHYSLOC`.`locationID` AS `employerPhysicalLocationID`,`EMPPHYSLOC`.`locationAddress` AS `employerPhysicalAddress`,`EMPPHYSLOC`.`locationCity` AS `employerPhysicalCity`,`EMPPHYSLOC`.`locationState` AS `employerPhysicalState`,`EMPPHYSLOC`.`locationZipCode` AS `employerPhysicalZip`,`EMPMAILLOC`.`locationID` AS `employerMailLocationID`,`EMPMAILLOC`.`locationAddress` AS `employerMailAddress`,`EMPMAILLOC`.`locationCity` AS `employerMailCity`,`EMPMAILLOC`.`locationState` AS `employerMailState`,`EMPMAILLOC`.`locationZipCode` AS `employerMailZip`,`INSURPHYSLOC`.`locationID` AS `insurerPhysicalLocationID`,`INSURPHYSLOC`.`locationAddress` AS `insurerPhysicalAddress`,`INSURPHYSLOC`.`locationCity` AS `insurerPhysicalCity`,`INSURPHYSLOC`.`locationState` AS `insurerPhysicalState`,`INSURPHYSLOC`.`locationZipCode` AS `insurerPhysicalZip`,`INSURMAILLOC`.`locationID` AS `insurerMailLocationID`,`INSURMAILLOC`.`locationAddress` AS `insurerMailAddress`,`INSURMAILLOC`.`locationCity` AS `insurerMailCity`,`INSURMAILLOC`.`locationState` AS `insurerMailState`,`INSURMAILLOC`.`locationZipCode` AS `insurerMailZip`,`TPAPHYSLOC`.`locationID` AS `TPAphysicalLocationID`,`TPAPHYSLOC`.`locationAddress` AS `TPAphysicalAddress`,`TPAPHYSLOC`.`locationCity` AS `TPAphysicalCity`,`TPAPHYSLOC`.`locationState` AS `TPAphysicalState`,`TPAPHYSLOC`.`locationZipCode` AS `TPAphysicalZip`,`TPAMAILLOC`.`locationID` AS `TPAmailLocationID`,`TPAMAILLOC`.`locationAddress` AS `TPAmailAddress`,`TPAMAILLOC`.`locationCity` AS `TPAmailCity`,`TPAMAILLOC`.`locationState` AS `TPAmailState`,`TPAMAILLOC`.`locationZipCode` AS `TPAmailZip`,`EMP`.`officePhone` AS `employerOfficePhone`,`EMP`.`tollFreePhone` AS `employerTollFreePhone`,`EMP`.`faxNumber` AS `employerFax`,`INSUR`.`officePhone` AS `insurerOfficePhone`,`INSUR`.`tollFreePhone` AS `insurerTollFreePhone`,`INSUR`.`faxNumber` AS `insurerFax`,`TPA`.`officePhone` AS `TPAofficePhone`,`TPA`.`tollFreePhone` AS `TPAtollFreePhone`,`TPA`.`faxNumber` AS `TPAfax` from ((((((((((((((((((((((((`files` left join `adjusters` on((`files`.`adjusterID` = `adjusters`.`adjusterID`))) left join `applicants` on((`files`.`applicantID` = `applicants`.`applicantID`))) left join `locations` `APPPHYSLOC` on((`applicants`.`physicalLocationID` = `APPPHYSLOC`.`locationID`))) left join `locations` `APPMAILLOC` on((`applicants`.`mailingLocationID` = `APPMAILLOC`.`locationID`))) left join `locations` `ADJPHYSLOC` on((`adjusters`.`physicalLocationID` = `ADJPHYSLOC`.`locationID`))) left join `locations` `ADJMAILLOC` on((`adjusters`.`mailingLocationID` = `ADJMAILLOC`.`locationID`))) left join `locations` `ADJBILLLOC` on((`adjusters`.`billingLocationID` = `ADJBILLLOC`.`locationID`))) left join `companies` `EMP` on((`files`.`employerID` = `EMP`.`companyID`))) left join `companies` `INSUR` on((`files`.`insurerID` = `INSUR`.`companyID`))) left join `companies` `TPA` on((`files`.`TPAid` = `TPA`.`companyID`))) left join `lawyers` `AA` on((`files`.`AAid` = `AA`.`lawyerID`))) left join `lawyers` `GLDA` on((`files`.`GLDAid` = `GLDA`.`lawyerID`))) left join `companies` `ADJ` on((`ADJ`.`companyID` = `adjusters`.`adjusterCompanyID`))) left join `locations` `EMPPHYSLOC` on((`EMP`.`physicalLocationID` = `EMPPHYSLOC`.`locationID`))) left join `locations` `EMPMAILLOC` on((`EMP`.`mailingLocationID` = `EMPMAILLOC`.`locationID`))) left join `locations` `INSURPHYSLOC` on((`INSUR`.`physicalLocationID` = `INSURPHYSLOC`.`locationID`))) left join `locations` `INSURMAILLOC` on((`INSUR`.`mailingLocationID` = `INSURMAILLOC`.`locationID`))) left join `locations` `TPAPHYSLOC` on((`TPA`.`physicalLocationID` = `TPAPHYSLOC`.`locationID`))) left join `locations` `TPAMAILLOC` on((`TPA`.`mailingLocationID` = `TPAMAILLOC`.`locationID`))) left join `locations` `AAPHYSLOC` on((`AA`.`physicalLocationID` = `AAPHYSLOC`.`locationID`))) left join `locations` `AAMAILLOC` on((`AA`.`mailingLocationID` = `AAMAILLOC`.`locationID`))) left join `firms` `AAF` on((`files`.`AAfirmID` = `AAF`.`firmID`))) left join `locations` `AAFPL` on((`AAFPL`.`locationID` = `AAF`.`physicalLocationID`))) left join `locations` `AAFML` on((`AAFML`.`locationID` = `AAF`.`mailingLocationID`)));
我確認,也適用於我,無需轉義'\'' – 2014-10-09 05:10:58
太棒了!那是我的問題。謝謝! – 2014-10-09 05:13:44