Take the 2-minute tour ×
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.

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

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
add comment

2 Answers 2

up vote 4 down vote accepted

g/somepattern/+d

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

foo     
bar 
somepattern 
baz 
someotherpattern
share|improve this answer
    
Thanks! Exactly what I needed :D –  krack krackerz Feb 13 '12 at 18:09
add comment

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
1  
Great site! Thanks. –  krack krackerz Feb 13 '12 at 18:10
add comment

Your Answer

 
discard

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.