Skip to content

"csvtk --show-row-number concat" does not print row number column. #360

Description

@derekmahar

In csvtk v0.37.0, csvtk --show-row-number concat does not print the row number column:

$ printf "a,b\n1,2\n" | csvtk --show-row-number concat
a,b
1,2

By comparison, csvtk --show-row-number cut does print the row number column:

$ printf "a,b\n1,2\n" | csvtk --show-row-number cut --fields 1,2
row,a,b
1,1,2
$ csvtk version
csvtk v0.37.0

Activity

  1. shenwei356 commented on May 2, 2026

    @shenwei356
    Owner

    Only a few commands support that flag (see the appendix below). And other commands needing the row number can be piped to one of these commands, like

    $ printf "a,b\n1,2\n" | csvtk concat - <(printf "a,b\n10,20\n") | csvtk cut -f 1- -Z
    row,a,b
    1,1,2
    2,10,20
    

    But I've enabled concat to support it now.

    $ printf "a,b\n1,2\n" | csvtk concat - <(printf "a,b\n10,20\n") -Z
    row,a,b
    1,1,2
    2,10,20
    
    $ printf "a,b\n1,2\n" | csvtk concat - <(printf "a,b\n10,20\n") -Z -H
    1,a,b
    2,1,2
    3,a,b
    4,10,20
    
    $ printf "a,b\n1,2\n" | csvtk concat - <(printf "a,b\n10,20\n") -U
    1,2
    10,20
    
    $ printf "a,b\n1,2\n" | csvtk concat - <(printf "a,b\n10,20\n") -Z -U
    1,1,2
    2,10,20
    

    I also make concat accept one input file now.

    $ printf "a,b\n1,2\n" | csvtk concat -Z
    row,a,b
    1,1,2
    

    appendix:

    $ rg config.ShowRowNumber
    csvtk/cmd/csv2xlsx.go
    91:                             ShowRowNumber: config.ShowRowNumber,
    
    csvtk/cmd/sample.go
    96:                             ShowRowNumber: printLineNumber || config.ShowRowNumber,
    
    csvtk/cmd/pretty.go
    210:                    ShowRowNumber: config.ShowRowNumber,
    286:                            if config.ShowRowNumber {
    295:                                            if config.ShowRowNumber {
    303:                                            if config.ShowRowNumber {
    318:                                            if config.ShowRowNumber {
    355:                                            if config.ShowRowNumber {
    373:                                            if config.ShowRowNumber {
    
    csvtk/cmd/cut.go
    126:                    ShowRowNumber:      config.ShowRowNumber,
    
    csvtk/cmd/csv2tab.go
    68:                             ShowRowNumber: config.ShowRowNumber,
    
    csvtk/cmd/filter2.go
    193:            showRowNumber := printLineNumber || config.ShowRowNumber
    
    csvtk/cmd/head.go
    71:             printLineNumber := config.ShowRowNumber
    
    csvtk/cmd/del-quotes.go
    76:                     ShowRowNumber: config.ShowRowNumber,
    
    csvtk/cmd/filter.go
    97:             showRowNumber := printLineNumber || config.ShowRowNumber
    
    csvtk/cmd/tab2csv.go
    69:                             ShowRowNumber: config.ShowRowNumber,
    
    csvtk/cmd/grep.go
    82:             printLineNumber := getFlagBool(cmd, "line-number") || config.ShowRowNumber
    
    
  2. derekmahar commented on May 2, 2026

    @derekmahar
    Author

    Thank you for this change. This will resolve the inconsistency between csvtk concat --show-row-number and its help documentation (--help) which specifies that --show-row-number is a global flag which applies to all commands.

    In csvtk v0.37.0 and earlier, does csvtk concat require at least two input files? Like in my example above, I've often used that command with only one input source, usually standard input.

  3. shenwei356 commented on May 2, 2026

    @shenwei356
    Owner

    It accepts one file before but needs to load all data in memory and then dump to output. Today's change make it more menory-effcient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions