You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: cmd/csvcols/csvcols.go
+15-19Lines changed: 15 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,3 @@
1
-
//
2
1
// csvcols - is a command line that takes each argument in order and outputs a line in CSV format.
3
2
// It can also take a delimiter and line of text splitting it into a CSV formatted set of columns.
4
3
//
@@ -16,7 +15,6 @@
16
15
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
17
16
//
18
17
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19
-
//
20
18
package main
21
19
22
20
import (
@@ -134,7 +132,6 @@ Using options filter a 3 column CSV file for columns 1,3 into 2col.csv
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
16
15
//
17
16
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
18
-
//
19
17
package main
20
18
21
19
import (
@@ -156,7 +154,6 @@ You can also search for phrases in columns.
156
154
{app_name} {version}
157
155
`
158
156
159
-
160
157
// Standard Options
161
158
showHelpbool
162
159
showLicensebool
@@ -209,7 +206,6 @@ func main() {
209
206
flag.BoolVar(&newLine, "nl", true, "include trailing newline from output")
210
207
flag.BoolVar(&newLine, "newline", true, "include trailing newline from output")
211
208
212
-
213
209
// App Options
214
210
flag.IntVar(&col, "col", 0, "column to search for match in the CSV file")
215
211
flag.IntVar(&col, "cols", 0, "column to search for match in the CSV file")
@@ -226,7 +222,8 @@ func main() {
226
222
flag.StringVar(&stopWordsOption, "stop-words", "", "use the colon delimited list of stop words")
227
223
flag.BoolVar(&skipHeaderRow, "skip-header-row", true, "skip the header row")
228
224
flag.BoolVar(&allowDuplicates, "allow-duplicates", true, "allow duplicates when searching for matches")
229
-
flag.BoolVar(&trimSpaces, "trimspace,trimspaces", false, "trim spaces around cell values before comparing")
225
+
flag.BoolVar(&trimSpaces, "trimspace", false, "trim spaces around cell values before comparing")
226
+
flag.BoolVar(&trimSpaces, "trimspaces", false, "trim spaces around cell values before comparing")
230
227
flag.BoolVar(&lazyQuotes, "use-lazy-quotes", false, "use lazy quotes on CSV input")
231
228
flag.BoolVar(&trimLeadingSpace, "trim-leading-space", false, "trim leadings space in field(s) for CSV input")
232
229
@@ -241,25 +238,24 @@ func main() {
241
238
out:=os.Stdout
242
239
eout:=os.Stderr
243
240
244
-
ifinputFName!="" {
245
-
in, err:=os.Open(inputFName)
246
-
iferr!=nil {
247
-
fmt.Fprintln(eout, err)
248
-
os.Exit(1)
249
-
}
250
-
deferin.Close()
251
-
252
-
}
241
+
ifinputFName!="" {
242
+
in, err=os.Open(inputFName)
243
+
iferr!=nil {
244
+
fmt.Fprintln(eout, err)
245
+
os.Exit(1)
246
+
}
247
+
deferin.Close()
253
248
254
-
ifoutputFName!="" {
255
-
out, err:=os.Create(outputFName)
256
-
iferr!=nil {
257
-
fmt.Fprintln(eout, err)
258
-
os.Exit(1)
259
249
}
260
-
deferout.Close()
261
-
}
262
250
251
+
ifoutputFName!="" {
252
+
out, err=os.Create(outputFName)
253
+
iferr!=nil {
254
+
fmt.Fprintln(eout, err)
255
+
os.Exit(1)
256
+
}
257
+
deferout.Close()
258
+
}
263
259
264
260
// Process options
265
261
ifshowHelp {
@@ -321,7 +317,7 @@ if outputFName != "" {
321
317
break
322
318
}
323
319
iferr!=nil {
324
-
if!quiet {
320
+
if!quiet {
325
321
fmt.Fprintf(eout, "%d %s\n", lineNo, err)
326
322
}
327
323
} else {
@@ -347,7 +343,7 @@ if outputFName != "" {
347
343
ifstrings.Contains(src, target) {
348
344
err:=csvOut.Write(record)
349
345
iferr!=nil {
350
-
if!quiet {
346
+
if!quiet {
351
347
fmt.Fprintf(eout, "%d %s\n", lineNo, err)
352
348
}
353
349
}
@@ -360,7 +356,7 @@ if outputFName != "" {
360
356
}
361
357
err:=csvOut.Write(record)
362
358
iferr!=nil {
363
-
if!quiet {
359
+
if!quiet {
364
360
fmt.Fprintf(eout, "%d %s\n", lineNo, err)
365
361
}
366
362
}
@@ -369,7 +365,7 @@ if outputFName != "" {
369
365
ifstrings.Compare(src, target) ==0 {
370
366
err:=csvOut.Write(record)
371
367
iferr!=nil {
372
-
if!quiet {
368
+
if!quiet {
373
369
fmt.Fprintf(eout, "%d %s\n", lineNo, err)
374
370
}
375
371
}
@@ -379,7 +375,7 @@ if outputFName != "" {
379
375
break
380
376
}
381
377
} else {
382
-
if!quiet {
378
+
if!quiet {
383
379
fmt.Fprintf(eout, "%d line skipped, missing column %d\n", lineNo, col)
0 commit comments