1

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`
Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
saimmm0710
  • 73
  • 5

2 Answers2

2

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.

mitchnegus
  • 85
  • 5
1

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.

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175