5

Assume I have a big file, ~1k lines, and I need to delete the line after some pattern, lets call it: somePatern.

Conditions:

  • cannot be done by hand (no searching -- /somePattern, and/or manually moving down one line and deleting).
  • preferably a single liner.
  • line after the line that contains the pattern has to be gone (no empty line)
  • has to be UNIX compatible (I use Debian but need it for UNIX -- great if works on both)

Also if anyone has a link to a site where I can learn this and more regex stuff that be awesome! (But not a beginners type of tut, I have that down, courtesy of vimtutor and others.)

8

g/somepattern/+d

In the following example baz was removed. (I only verified with Vim though.)

foo     
bar 
somepattern 
baz 
someotherpattern
3

Take a look here in section 3.2 "Range of Operation, Line Addressing and Marks". It seems that Vim commands can accept a line range in front of them. By specifying the line range you restrict the command execution to this particular part of text only.

For example:

/pattern[/] the next line where text "pattern" matches

?pattern[?] the previous line where text "pattern" matches

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.