How to replace the symbol special characters using find command?
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How to replace the symbol special characters using find command?
Hi guys,
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.
find /rezsystem/jboss/jboss_2/server/default/deploy/SERVERNAME.ear -name "*.properties" -type f -exec sed -i 's/<REPLACE THIS KEY>/<WITH THIS KEY>/g' {} \;
AND if there is "//" im using this
find /home/uploads/chathu/eventinfocus.ear -name "*.properties" -type f -exec sed -i 's$http://<REPLACE THIS KEY.COM>$http://<WITH THIS KEY>COM>$' {} \;
above two command not working for some special character, please give me idea to how to do it if there are special characters.
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.
Hi friend,
I have run following command to change it. bu i got following error. Command I have run=
find /home/uploads/DntUseThis_ear/abcd.ear -name "*.properties" -type f -print |xargs sed -i 's/webres.label.cancellation.hotels.amend.phone1 = <b>+971 4 3434747</b>/webres.label.cancellation.hotels.amend.phone1 = <b>+971 4 3434747</b>,1234567 hello we edit/g'
I got following error
sed: couldn't open file ebres.label.cancellation.hotels.amend.phone1 = <b>+971 4 3434747</b>,1234567 hello we edit/g: No such file or directory
First I want to tell you If you want to change a string like this inform 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.
Code:
find /home/uploads/DntUseThis_ear/abcd.ear -name "*.properties" -type f -print |xargs sed -i 's/webres\.label\.cancellation\.hotels\.amend\.phone1 = <b>+971 4 3434747<\/b>/&1234567 hello we edit/g'
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.
If you want to change webres.label.cancellation.hotels.amend.phone1 = <b>+971 4 3434747</b> into webres.label.cancellation.hotels.amend.phone1 = <b>+971 5 3396361</b>
Try this
Code:
find /home/uploads/DntUseThis_ear/lamarholidays.ear -name "*.properties" -type f -exec sed -i 's/webres\.label\.cancellation\.hotels\.amend\.phone1 = <b>+971 4 3434747<\/b>/webres\.label\.cancellation\.hotels\.amend\.phone1 = <b>+971 5 3396361<\/b>/g' {} \;
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.