How can I replace specific characters in a file using shell scripting?
You can use the sed command in the shell to replace specific characters in a file. Here is an example:
Suppose there is a file named example.txt with the following content:
Hello, world!
This is an example file.
Now, we want to replace “world” with “universe” in the file, you can use the following command:
sed -i 's/world/universe/g' example.txt
In the above command, the -i option indicates directly modifying the file content, s/world/universe/g indicates replacing world with universe, and g represents global replacement (meaning all occurrences of world in a line will be replaced). After executing the above command, the content of example.txt will be:
Hello, universe!
This is an example file.