I have a renamed js file which I have to call in each of my php pages. Now I want to replace that old name with the new one using shell. what iam using is this:
sed -i ’s/old/new/g’ *
but this is giving the following error:
sed: -e expression #1, char 1: unknown command:
How can I do this replacement?
Remove all the files you don't want to edit by selecting them and pressing DEL, then right-click the remaining files and choose Open all. Now go to Search > Replace or press CTRL+H, which will launch the Replace menu. Here you'll find an option to Replace All in All Opened Documents.
To replace content in a file, you must search for the particular file string. The 'sed' command is used to replace any string in a file using a bash script. This command can be used in various ways to replace the content of a file in bash. The 'awk' command can also be used to replace the string in a file.
s/search/replace/g — this is the substitution command. The s stands for substitute (i.e. replace), the g instructs the command to replace all occurrences.
sed -i.bak 's/old/new/g' *.php
to do it recursively
find /path -type f -iname '*.php' -exec sed -i.bak 's/old/new/' "{}" +;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With