]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
column: support ranges when addressing columns by numbers
authorKarel Zak <kzak@redhat.com>
Mon, 20 Jun 2022 11:25:59 +0000 (13:25 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 20 Jun 2022 11:25:59 +0000 (13:25 +0200)
Fixes: https://github.com/util-linux/util-linux/issues/1723
Signed-off-by: Karel Zak <kzak@redhat.com>
text-utils/column.1.adoc
text-utils/column.c

index 99559ac46b2973fa351a1b1a273073d02f1b1e4d..a940a0536dde854a3de48627f3ede61a62428b9b 100644 (file)
@@ -70,6 +70,7 @@ column names as defined by *--table-columns*, or names defined by
 *--table-column* or it's column number in order as specified by input. It's
 possible to mix names and numbers. The special placeholder '0' (e.g. -R0) may
 be used to specify all columns and '-1' (e.g. -R -1) to specify the last visible column.
+It's possible to use ranges like '1-5' when addressing columns by numbers.
 
 *-J, --json*::
 Use JSON output format to print the table, the option *--table-columns* is required and the option *--table-name* is recommended.
index 50b24bd58dab31f53fffe18dec63e4235605f06d..cb40d8f26c2f22c5f941035e0f5bfaafbfb401be 100644 (file)
@@ -348,10 +348,24 @@ static void apply_columnflag_from_list(struct column_control *ctl, const char *l
 
        /* apply to columns specified by name */
        STRV_FOREACH(one, all) {
+               int low = 0, up = 0;
+
                if (strcmp(*one, "-") == 0) {
                        unnamed = 1;
                        continue;
                }
+
+               /* parse range (N-M) */
+               if (strchr(*one, '-') && parse_range(*one, &low, &up, 0) == 0) {
+                       for (; low <= up; low++) {
+                               cl = scols_table_get_column(ctl->tab, low);
+                               if (cl)
+                                       column_set_flag(cl, flag);
+                       }
+                       continue;
+               }
+
+               /* one item in the list */
                cl = string_to_column(ctl, *one);
                if (cl)
                        column_set_flag(cl, flag);