From 112140c24a489bce3c9e40f04a479226a0f6c57d Mon Sep 17 00:00:00 2001 From: Noboru Saito Date: Sun, 27 Oct 2024 17:04:19 +0900 Subject: [PATCH 1/2] Add extension support for text format Add support for determining text format by extension. Add text format description to README.md. --- README.md | 35 +++++++++++++++++++++++++++++++++++ reader.go | 1 + 2 files changed, 36 insertions(+) diff --git a/README.md b/README.md index 2d2ad1c..ec5e6d9 100644 --- a/README.md +++ b/README.md @@ -185,6 +185,7 @@ trdsql -o[output format] -t [input filename] * `-iyaml` YAML format for input. * `-itbln` TBLN format for input. * `-iwidth` width specification format for input. +* `-itext` text format for input. #### 3.2.1. Input options @@ -193,6 +194,7 @@ trdsql -o[output format] -t [input filename] * `-ijq` **string** jq expression string for input(JSON/JSONL only). * `-ilr` **int** limited number of rows to read. * `-inull` **string** value(string) to convert to null on input. +* `-inum` add row number column. * `-ir` **int** number of rows to preread. (default 1) * `-is` **int** skip header row. @@ -792,6 +794,39 @@ But `-id " "` does not recognize spaces in columns very well. `-iwidth` recognizes column widths and space separators. +### TEXT + +The `-itext` option or files with “.text”extension are in text format. + +This is a one line to one column format. +A blank line is also a line, unlike the `CSV` format. + +```console +$ cat test.text +a + +b + +c +$ trdsql -itext "SELECT * FROM test.text" +a + +b + +c +``` + +It is useful in conjunction with the -inum option. + +```console +$ trdsql -inum "SELECT * FROM test.text" +1,a +2, +3,b +4, +5,c +``` + ### 4.15. Raw output `-oraw` is Raw Output. diff --git a/reader.go b/reader.go index bc6b6b7..41a26cc 100644 --- a/reader.go +++ b/reader.go @@ -18,6 +18,7 @@ var extToFormat map[string]Format = map[string]Format{ "TSV": TSV, "PSV": PSV, "WIDTH": WIDTH, + "TEXT": TEXT, } // ReaderFunc is a function that creates a new Reader. From 253bdbc0444cdadf26919b160105a3edefc55b7e Mon Sep 17 00:00:00 2001 From: Noboru Saito Date: Mon, 28 Oct 2024 10:44:52 +0900 Subject: [PATCH 2/2] Update Table of Contents --- README.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ec5e6d9..f855c84 100644 --- a/README.md +++ b/README.md @@ -51,9 +51,10 @@ For usage as a library, please refer to the [godoc](https://pkg.go.dev/github.co * 4.12. [YAML](#yaml) * 4.13. [TBLN](#tbln) * 4.14. [WIDTH](#width) - * 4.15. [Raw output](#raw-output) - * 4.16. [ASCII Table & MarkDown output](#ascii-table-&-markdown-output) - * 4.17. [Vertical format output](#vertical-format-output) + * 4.15. [TEXT](#text) + * 4.16. [Raw output](#raw-output) + * 4.17. [ASCII Table & MarkDown output](#ascii-table-&-markdown-output) + * 4.18. [Vertical format output](#vertical-format-output) * 5. [SQL](#sql) * 5.1. [SQL function](#sql-function) * 5.2. [JOIN](#join) @@ -794,7 +795,7 @@ But `-id " "` does not recognize spaces in columns very well. `-iwidth` recognizes column widths and space separators. -### TEXT +### 4.15. TEXT The `-itext` option or files with “.text”extension are in text format. @@ -827,7 +828,7 @@ $ trdsql -inum "SELECT * FROM test.text" 5,c ``` -### 4.15. Raw output +### 4.16. Raw output `-oraw` is Raw Output. It is used when "escape processing is unnecessary" in CSV output. @@ -852,7 +853,7 @@ $ trdsql -oraw -od "\t|\t" -db pdb "SELECT * FROM test.csv" 3 | Apple ``` -### 4.16. ASCII Table & MarkDown output +### 4.17. ASCII Table & MarkDown output `-oat` is ASCII table output. @@ -880,7 +881,7 @@ $ trdsql -omd "SELECT * FROM test.csv" The `-onowrap` option does not wrap long columns in `at` or `md` output. -### 4.17. Vertical format output +### 4.18. Vertical format output -ovf is Vertical format output("column name | value" vertically).