Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


  • 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.)

share|improve this question
Not exactly what you asked for, but still I think it can be useful: rayninfo.co.uk/vimtips.html – johnny Feb 13 '12 at 11:08
up vote 5 down vote accepted


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

share|improve this answer
Thanks! Exactly what I needed :D – krack krackerz Feb 13 '12 at 18:09

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

share|improve this answer
Great site! Thanks. – krack krackerz Feb 13 '12 at 18:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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