diff --git a/src/uu/cut/src/cut.rs b/src/uu/cut/src/cut.rs index 2a3196d002e..7488020560f 100644 --- a/src/uu/cut/src/cut.rs +++ b/src/uu/cut/src/cut.rs @@ -204,11 +204,8 @@ fn cut_fields_implicit_out_delim( let mut print_delim = false; if delim_search.peek().is_none() { - if !only_delimited { + if !only_delimited && line[line.len() - 1] == newline_char { out.write_all(line)?; - if line[line.len() - 1] != newline_char { - out.write_all(&[newline_char])?; - } } return Ok(true); diff --git a/tests/by-util/test_cut.rs b/tests/by-util/test_cut.rs index 57e6666d304..e468745f6e9 100644 --- a/tests/by-util/test_cut.rs +++ b/tests/by-util/test_cut.rs @@ -265,3 +265,12 @@ fn test_multiple() { assert_eq!(result.stdout_str(), "b\n"); assert_eq!(result.stderr_str(), ""); } + +#[test] +fn test_newline_delimited() { + new_ucmd!() + .args(&["-f", "1", "-d", "\n"]) + .pipe_in("a:1\nb:") + .succeeds() + .stdout_only_bytes("a:1\n"); +}