I need to way to replace special characters using find command, usually im using following two command, but when there is special characters such as "#,&,<,>,<br> it not replacing, sometimes it add to existing one. See the below command im using, please give me a solution for it.

I have used properties* if filenames like properties100, properties1023, properties1569 etc
you can use REGEXP according to your requirement.

lahirushanaka

03-06-2013 07:35 AM

Thank you very much pavi_kanetkar. IS this possible to replace 100 of files at a time?

fortran

03-06-2013 07:54 AM

That's why I have used xargs for multiple files.
This command is used when you want to pass a lot of arguments to one command. xargs will combine the single line output of find and run commands with multiple arguments.

First I want to tell you If you want to change a string like thisinform to informant.
You do not have only this option.

Code:

sed 's/inform/informant/g' /path/og/file

You can use this too

Code:

sed 's/inform/&ant/g' /path/og/file

where '&' is the symbol of string what do you want to replace.

You are getting the error because you have not used backslash(\) before dot (.).
Linux is taking dot as special characters and it is using it as a regular expression. So when you have special character like dot or slash, you have to put backslash before it. It works as a escape character.

Now above command will replace "webres.label.cancellation.hotels.amend.phone1 = <b>+971 4 3434747</b>" with "webres.label.cancellation.hotels.amend.phone1 = <b>+971 4 3434747</b>1234567 hello we edit".
I haven't done it practically, I am just giving you hint. If you get any error, paste here.

lahirushanaka

03-19-2013 07:00 AM

HI,

Still im facing to above problems. it not replace when i run following command.

In your code you have used webres\.label\.cancellation\.hotels\.amend\.phone1 = \<\b\>\+971 4 3434747<\/b\> for old string, if you see this carefully, you have used \<\b\> for initial bold syntax, you should not give backspace before b, it is not able to find it that's why it is not able to replace it.
Second do not use backspace before <, >, & +. These are not used as escape characters just like you have done with =, you haven't used backspace for = and it is correct.