diff --git a/src/uu/od/src/od.rs b/src/uu/od/src/od.rs index 13476bf0760..79e497b1d31 100644 --- a/src/uu/od/src/od.rs +++ b/src/uu/od/src/od.rs @@ -625,7 +625,7 @@ fn extract_strings_from_input( match radix { Radix::NoPrefix => writeln!(writer, "{string_content}"), Radix::Decimal => writeln!(writer, "{offset:07} {string_content}"), - Radix::Hexadecimal => writeln!(writer, "{offset:07x} {string_content}"), + Radix::Hexadecimal => writeln!(writer, "{offset:06x} {string_content}"), Radix::Octal => writeln!(writer, "{offset:07o} {string_content}"), } }; diff --git a/tests/by-util/test_od.rs b/tests/by-util/test_od.rs index 4aa0dc8c596..66d89fa1a5f 100644 --- a/tests/by-util/test_od.rs +++ b/tests/by-util/test_od.rs @@ -1404,6 +1404,14 @@ fn test_od_strings_option() { .succeeds() .stdout_is("0000001 hello\n0000007 world\n"); + // Hexadecimal offsets use 6 digits, as in the normal dump + new_ucmd!() + .arg("-Ax") + .arg("-S3") + .pipe_in(b"\x01hello\x00world\x00ab\x00") + .succeeds() + .stdout_is("000001 hello\n000007 world\n"); + // Test with -S10 to show only strings with minimum length new_ucmd!() .arg("-S10")