Possible Duplicate:
I specifically want to delete my grep output string from the text file

I'm a little bit new with Linux and I have a problem. I have a text file called file_a.txt My first command

grep -A 12 ".production =" file_a.txt

The output is a few block. Each block of string contains 13 rows

I specifically want to delete all the block of strings I got with the grep command from the original file file_a.txt I do not want to send the grep output to a new file. Also I do not want to to use grep -v because it will not work in my case.

I have tried something like things like this, but nothing is working:

cut < grep -A 12 ".production =" file_a.txt

sed -i '/grep -A 12 ".production ="/d' file_a.txt

marked as duplicate by Michael Mrozek Oct 9 '12 at 13:35

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

migrated from stackoverflow.com Oct 9 '12 at 11:58

This question came from our site for professional and enthusiast programmers.

  • what happened with my answer??? – Hola Soy Edu Feliz Navidad Oct 9 '12 at 10:36
  • @HolaSoyEduFelizNavidad no deleted answer showing up, so you/the browser probably didn't successfully post it. I checked, you didn't post at the wrong question (at least on Stack Overflow) – sehe Oct 9 '12 at 10:40
  • @Clayton please don't cross post, as a Unix SE moderator I'm requesting this be closed here and moved there. – xenoterracide Oct 9 '12 at 11:16
  • @xenoterracide huh. Why didn't you cast a close-vote (offtopic, SU) then? Also, this is entirely appropriate for Stack Overflow IMO. There is a certain amount of overlap, as shell scripting is considered programming too – sehe Oct 9 '12 at 11:26
  • @sehe note SU is not Unix, and it is appropriate but cross posting is frowned upon. we really don't need people posting a verbatim copy of the same question on SO, SU, SF, AU, and U&L (within 10 minutes) just so they can get points or a faster answer. I didn't vote to close offtopic because it's technically? not. I think there ought to be rules about crossposting and flag as cross site duplicate... but it's a pipe dream. – xenoterracide Oct 9 '12 at 11:36

I think you are looking for this:

sed -i '/.production =/,+12d' file_a.txt

When sed finds you patterns it "deletes" 12 lines

(warning, modifies file_a.txt in-place)

  • 1
    Except the next 12 rows need to be deleted as well. – Ignacio Vazquez-Abrams Oct 9 '12 at 10:36
  • @IgnacioVazquez-Abrams whoops, added – sehe Oct 9 '12 at 10:38
  • 1
    @sehe +1 for fast posting and editing ! :) – Kent Oct 9 '12 at 10:39
sed -i '/\.production =/,+12d' file_a.txt

would do the job