0

I have a list.txt file with a couple of lines like:

this line 1
this line 2
this line 3
this line 4
this line 5
this line 6

I want to delete from line 1 to line 2 with the ex command without using vim editor, I want use the ex command if that is possible

I just know how to delete specific word like break from the list:

$ ex +g/^"break"$/d -cwq list.txt
romainl
  • 186,200
  • 21
  • 280
  • 313

1 Answers1

1

Below the command which displays the requested transformations.

$  ex list.txt +'1,2d' +'g/^break$/d' +'%s/this//g' +'wq'

Arguments of the given ex command:

From line number (1) until (,) linenumber (2) inclusive, delete (d) line:

+'1,2d'
  • Delete a specific line. For all line from beginning-to-the-end-of-file (g) match on starting line (^) with text (break) followed directly with end of line ($), do delete (d)
+'g/^break$/d'
  • For all lines (%) subsitute (s) matching (/) something (this) (/) [with nothing] (/) also if multiple times one a line (g)
+'%s/this//g'
  • Combined with the ex commands to write and quit:
 +'wq'

INPUT: list.txt

this line 1
this line 2
this line 3
this line 4
break
this line 5
this line 6

RESULTING OUTPUT: list.txt

 line 3
 line 4
 line 5
 line 6

Good luck

S_IROTH
  • 210
  • 1
  • 5