How to use SED to quickly edit text on a file or a batch of file.
1. Open the terminal from search bar once you click on
2. Use the cat command to view the file you want to update. In this case the file name is hello_world.txt.
3. To change the first instance of a string using SED we will be using the following syntax: sed -option 'action/name/NAME/' file.txt. We will be using the "-i" option to save the file.
sudo sed -i 's/hello world/HELLO WORLD/' hello_world.txt
4. Use cat hello_world.txt to see the output to check if the file has been modified.
This is more useful if you need to make a change in a batch of files. You can use the global action.
sudo sed -i 's/hello world/HELLO WORLD/g' /some_directory/*.txt
Please sign in to leave a comment.