diff --git a/Base/usr/share/man/man1/cut.md b/Base/usr/share/man/man1/cut.md index e93e917336c..7fbed656c99 100644 --- a/Base/usr/share/man/man1/cut.md +++ b/Base/usr/share/man/man1/cut.md @@ -23,6 +23,7 @@ With no FILE, or when FILE is -, read standard input. * `-b` `--bytes=list`: Select only these bytes * `-f` `--fields=list`: select only these fields; also print any line that contains no delimiter character * `-d` `--delimiter=delim`: use `delim` instead of `tab` for field delimiter +* `-s`, `only-delimited`: suppress lines which don't contain any field delimiter characters ## Examples diff --git a/Userland/Utilities/cut.cpp b/Userland/Utilities/cut.cpp index 3931ed38ebe..c6824ea0318 100644 --- a/Userland/Utilities/cut.cpp +++ b/Userland/Utilities/cut.cpp @@ -134,11 +134,13 @@ static void process_line_bytes(StringView line, Vector const& ranges) outln(); } -static void process_line_fields(StringView line, Vector const& ranges, char delimiter) +static void process_line_fields(StringView line, Vector const& ranges, char delimiter, bool only_print_delimited_lines) { auto string_split = DeprecatedString(line).split(delimiter, SplitBehavior::KeepEmpty); if (string_split.size() == 1) { - outln("{}", line); + if (!only_print_delimited_lines) + outln("{}", line); + return; } @@ -157,6 +159,7 @@ ErrorOr serenity_main(Main::Arguments arguments) DeprecatedString byte_list = ""; DeprecatedString fields_list = ""; DeprecatedString delimiter = "\t"; + bool only_print_delimited_lines = false; Vector files; @@ -165,6 +168,7 @@ ErrorOr serenity_main(Main::Arguments arguments) args_parser.add_option(byte_list, "select only these bytes", "bytes", 'b', "list"); args_parser.add_option(fields_list, "select only these fields", "fields", 'f', "list"); args_parser.add_option(delimiter, "set a custom delimiter", "delimiter", 'd', "delimiter"); + args_parser.add_option(only_print_delimited_lines, "suppress lines which don't contain any field delimiter characters", "only-delimited", 's'); args_parser.parse(arguments); bool selected_bytes = (byte_list != ""); @@ -249,7 +253,7 @@ ErrorOr serenity_main(Main::Arguments arguments) if (selected_bytes) { process_line_bytes(line, disjoint_ranges); } else if (selected_fields) { - process_line_fields(line, disjoint_ranges, delimiter[0]); + process_line_fields(line, disjoint_ranges, delimiter[0], only_print_delimited_lines); } else { VERIFY_NOT_REACHED(); }