diff --git a/src/sed/processor.rs b/src/sed/processor.rs index 7b4277e..45d6b26 100644 --- a/src/sed/processor.rs +++ b/src/sed/processor.rs @@ -695,9 +695,13 @@ pub fn process_all_files( .map_err_context(|| format!("error opening input file {}", path.quote()))?; let output = in_place.begin(path)?; - if index == 0 || context.separate { + if context.separate || index == 0 { context.line_number = 0; reset_latched_address_ranges(&mut context.range_commands); + + // Reset hold space for separate file processing + context.hold.content.clear(); + context.hold.has_newline = true; } context.input_name = path.quote().to_string(); diff --git a/tests/by-util/test_sed.rs b/tests/by-util/test_sed.rs index 13a6576..b31fed7 100644 --- a/tests/by-util/test_sed.rs +++ b/tests/by-util/test_sed.rs @@ -380,6 +380,10 @@ check_output!( pattern_hold_append_swap, ["-e", r"2h;3H;4g;5G;6x;6p;6x;6p", LINES1] ); +check_output!( + pattern_swap_separate, + ["--separate", r"4x;6x", LINES1, LINES2] +); check_output!(pattern_next_output, ["-e", r"4n", LINES1]); check_output!(pattern_next_no_output, ["-n", "-e", r"4n", LINES1]); check_output!(pattern_next_print_output, ["-e", r"4n;p", LINES1]); diff --git a/tests/fixtures/sed/output/pattern_swap_separate b/tests/fixtures/sed/output/pattern_swap_separate new file mode 100644 index 0000000..5de4c38 --- /dev/null +++ b/tests/fixtures/sed/output/pattern_swap_separate @@ -0,0 +1,23 @@ +l1_1 +l1_2 +l1_3 + +l1_5 +l1_4 +l1_7 +l1_8 +l1_9 +l1_10 +l1_11 +l1_12 +l1_13 +l1_14 +l2_1 +l2_2 +l2_3 + +l2_5 +l2_4 +l2_7 +l2_8 +l2_9