However in practice we need to remove some text from a file or from multiple files. Removing text from files manually is a tough task. Here is a sample example to do this:
Create a script
- Create a file like
SOME_NAME.sh
- Write following lines of code in that file
You can use any extension in place of txt according to your requirement.
Explanation
grep -v "YOUR_TEXT_TO_REMOVE" $thefile > $thefile.$$.tmp
returns the content of all .txt
files in that directory YOUR_TEXT_TO_REMOVE
and write that output in a tempfile then replace new file with that original one.
Running script
- To run script just run
sh SOME_NAME.sh
Enjoy !!!