@@ -435,6 +435,7 @@ fn process_file(
435435 ' lines: while let Some ( mut pattern) = reader. get_line ( ) ? {
436436 context. line_number += 1 ;
437437 context. substitution_made = false ;
438+ context. pattern_deleted = false ;
438439 // Set the script command from which to start.
439440 let mut current: Option < Rc < RefCell < Command > > > =
440441 if let Some ( action) = context. input_action . take ( ) {
@@ -494,6 +495,7 @@ fn process_file(
494495 // At range end replace pattern space with text and
495496 // start the next cycle.
496497 pattern. clear ( ) ;
498+ context. pattern_deleted = true ;
497499 if command. addr2 . is_none ( ) || context. last_address || reader. last_line ( ) ? {
498500 let text = extract_variant ! ( command, Text ) ;
499501 output. write_str ( text. as_ref ( ) ) ?;
@@ -503,6 +505,7 @@ fn process_file(
503505 'd' => {
504506 // Delete the pattern space and start the next cycle.
505507 pattern. clear ( ) ;
508+ context. pattern_deleted = true ;
506509 break ;
507510 }
508511 'D' => {
@@ -515,6 +518,7 @@ fn process_file(
515518 } else {
516519 // Same as d
517520 pattern. clear ( ) ;
521+ context. pattern_deleted = true ;
518522 break ;
519523 }
520524 }
@@ -653,7 +657,7 @@ fn process_file(
653657 current = command. next . clone ( ) ;
654658 }
655659
656- if !context. quiet {
660+ if !context. quiet && !context . pattern_deleted {
657661 write_chunk ( output, context, & pattern) ?;
658662 }
659663
0 commit comments