开发者

Using sed selectively

My dump file looks something like this...

--
-- Current开发者_如何学运维 Database: `Batch`
--

CREATE DATABASE /*!32312 IF NOT EXISTS*/ `Batch` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_bin */;

USE `Batch`;

--
-- Table structure for table `BATCH_JOB_EXECUTION`
--

DROP TABLE IF EXISTS `BATCH_JOB_EXECUTION`;
SET @saved_cs_client     = @@character_set_client;
SET character_set_client = utf8;
CREATE TABLE `BATCH_JOB_EXECUTION` (
  `JOB_EXECUTION_ID` bigint(20) NOT NULL,
  `VERSION` bigint(20) default NULL,

I want to change the DB name found in the create table and "use" statement to pd_Batch.

sed 's/Batch/pd_Batch/' test.sql

The above statement will do the needful. But I do not want any "Batch" word to be changed. It should change only the word found on the line starting with CREATE DATABASE or USE.

Update:

The by-product of this question is there is more than one DB in the test.sql file. So the following words needs to be prefixed with pd_

Batch
cash
country
rules
currency
state


sed '/CREATE DATABASE\|USE/s/Batch/pd_Batch/' test.sql
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜