user2841861
user2841861

Reputation: 443

search and replace part of string in file

I have a file that looks like this.

/n01/mysqlarch1/mysql-bin.000011
/n01/mysqlarch1/mysql-bin.000012
/n01/mysqlarch1/mysql-bin.000013
/n01/mysqlarch2/mysql-bin.000014
/n01/mysqlarch2/mysql-bin.000015
/n01/mysqlarch2/mysql-bin.000016

I want to be able to search for both mysqlarch1 and mysqlarch2 and replace with mysqldata1.

Therefore the file would end up looking like...

/n01/mysqldata1/mysql-bin.000011
/n01/mysqldata1/mysql-bin.000012
/n01/mysqldata1/mysql-bin.000013
/n01/mysqldata1/mysql-bin.000014
/n01/mysqldata1/mysql-bin.000015
/n01/mysqldata1/mysql-bin.000016

any help would be greatly appreciated.

Upvotes: 2

Views: 35

Answers (1)

anubhava
anubhava

Reputation: 786291

sed can do the job:

sed 's/mysqlarch[12]/mysqldata1/g' file
/n01/mysqldata1/mysql-bin.000011
/n01/mysqldata1/mysql-bin.000012
/n01/mysqldata1/mysql-bin.000013
/n01/mysqldata1/mysql-bin.000014
/n01/mysqldata1/mysql-bin.000015
/n01/mysqldata1/mysql-bin.000016

Upvotes: 1

Related Questions