I have a SQL text file on my Linux server, and I need to remove all lines starting by
INSERT INTO `mdl_logstore_standard_log`
I have a SQL text file on my Linux server, and I need to remove all lines starting by
INSERT INTO `mdl_logstore_standard_log`
Looks like a duplicate of this.
Following the "Better Solution" in the chosen answer there, you would likely want to consider using sed
. This will delete the lines without needing to open the file.
For your specific case, you can run
sed '/^INSERT INTO `mdl_logstore_standard_log`/d' text_file.sql > new_text_file.sql
where you'd replace text_file.sql
and new_text_file.sql
with your current file and the file with lines deleted. You may also want to consider looking at the -i
(or equivalent --in-place
) option if you'd prefer to overwrite your previous file with the new one.
You can achieve it with vim. Open the file, type :g and then make sure you run the following:
:g/^INSERT INTO `mdl_logstore_standard_log`/d
Explanation: - ^ is the start of the string, here means starts with - d at the end means delete - the pattern between the slashes is the pattern to find
If it looks good, hit :w to save your file.