Timeline for Delete the nth line from a matched string (which only occurs once in the file)
Current License: CC BY-SA 3.0
10 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| May 2, 2016 at 5:37 | comment | added | Rahul | @don_crissti - thanks how to achieve this using gnu awk ? could you please update on my answer ? | |
| May 1, 2016 at 15:05 | history | edited | Dani_l | CC BY-SA 3.0 | added 118 characters in body |
| May 1, 2016 at 11:07 | comment | added | don_crissti | @arzyfex - yours will fail too (see my first comment here). Basically, your awk - just like the sed here - will fail if there are multiple lines matching that aren't at least N+1 lines away from each other. However, since the question here is definitely about files with a single occurrence of pattern (OP says "delete this line" - so it's just one line), both answers here work. And let's just leave it like that. I'll ask a different question later on where I'll specify that pattern may occur on multiple, random lines (so a more general case as opposed to this particular case). | |
| May 1, 2016 at 5:22 | comment | added | Rahul | @Dani_l How can you say that "arzyfex's solution fails because all pattern lines remain", As OP has already said, it worked for him/her. | |
| Apr 30, 2016 at 20:08 | comment | added | Dani_l | @don_crissti I think part of the issue is undefined behavior for consecutive patterns - suppose you have 3 consecutive lines, according to the rule you have to delete line #3, but what about lines #4,#5 ? one interpretation would be to delete all 3 lines (last pattern +2 lines), but if last pattern is no more, does it still count for purpose of deleting #5? Are you supposed to delete a target if in same pass you deleted source for choosing the target? | |
| Apr 30, 2016 at 20:01 | comment | added | Dani_l | @don_crissti Add a good solution, and I'll delete mine. | |
| Apr 30, 2016 at 19:57 | comment | added | Zzrot | Exactly what I wanted. Thanks a lot for the help. :) | |
| Apr 30, 2016 at 19:55 | vote | accept | Zzrot | ||
| Apr 30, 2016 at 19:41 | comment | added | Dani_l | @don_crissti true, but then the awk solution doesn't work either, nor does the OP's awk matcher. arzyfex's solution fails because all pattern lines remain, whereas the OP clearly asked for n+2 to be deleted. | |
| Apr 30, 2016 at 19:30 | history | answered | Dani_l | CC BY-SA 3.0 |