How to Delete Lines With Grep in Unix
Using the grep command in Unix or Linux, you can delete certain lines from text-based files. This is useful you have many documents that contain the word "delete" added to a line that needs to be deleted. The grep command, which searches through text files for search strings, can pinpoint information that would otherwise take a lot of time to find manually. Grep will create new versions of the files with the offending phrases removed.
Instructions
-
-
1
Open your Unix or Linux terminal.
-
2
Type "grep -v WORD yourfile > yourfile.new" (without quotes). Replace "WORD" with the line you want to delete, based on the word. Replace "yourfile" with the file path or folder path you want to search, and "yourfile.new" with the new file name if the offending line is there.
-
-
3
Press "Enter."
-
1