@@ -43,7 +43,7 @@ SYNOPSIS
43
43
44
44
%s converts a set of command line args into columns output in CSV format.
45
45
It can also be used to filter input CSV and rendering only the column numbers
46
- listed on the commandline.
46
+ listed on the commandline (first column is 1 not 0)
47
47
`
48
48
49
49
examples = `
@@ -61,13 +61,13 @@ Example parsing a pipe delimited string into a CSV line
61
61
%s -delimiter "|" "1|2|3" >> 3col.csv
62
62
cat 3col.csv
63
63
64
- Filter a 10 column CSV file for columns 0,3,5 (left most column is number zero)
64
+ Filter a 10 column CSV file for columns 1,4,6 (left most column is number zero)
65
65
66
- cat 10col.csv | csvcols -col 0 3 5 > 3col.csv
66
+ cat 10col.csv | csvcols -col 1 4 6 > 3col.csv
67
67
68
- Filter a 10 columns CSV file for columns 0,3,5 from input file
68
+ Filter a 10 columns CSV file for columns 1,4,6 from input file
69
69
70
- %s -i 10col.csv -col 0 3 5 > 3col.csv
70
+ %s -i 10col.csv -col 1 4 6 > 3col.csv
71
71
`
72
72
73
73
// Standard Options
@@ -187,8 +187,13 @@ func main() {
187
187
columnNos := []int {}
188
188
for _ , arg := range args {
189
189
i , err := strconv .Atoi (arg )
190
+ // NOTE: We need to adjust from humans counting from 1 to counting from zero
191
+ i --
192
+ if i < 0 {
193
+ i = 0
194
+ }
190
195
if err != nil {
191
- fmt .Fprintf (os .Stderr , "Expected a column number (0 - n) , %q, %s\n " , arg , err )
196
+ fmt .Fprintf (os .Stderr , "Expected a column number in range of 1 to N , %q, %s\n " , arg , err )
192
197
os .Exit (1 )
193
198
}
194
199
columnNos = append (columnNos , i )
0 commit comments