mithrandie / csvq

SQL-like query language for csv
https://mithrandie.github.io/csvq
MIT License
1.5k stars 65 forks source link

"cvsq --format CSV --without-header" outputs blank line when CSV file contains only header (no data rows). #21

Closed derekmahar closed 4 years ago

derekmahar commented 4 years ago

Command cvsq --format CSV --without-header outputs an unnecessary blank line (newline) when the input CSV file contains only a header (no data rows).

$ printf "date,source_currency_code,target_currency_code,exchange_rate" |
 csvq --format CSV --without-header "SELECT * FROM STDIN"

$

By contrast, command cvsq --format CSV correctly outputs only the header:

$ printf "date,source_currency_code,target_currency_code,exchange_rate" |
csvq --format CSV "SELECT * FROM STDIN"
date,source_currency_code,target_currency_code,exchange_rate
$

This is a minor, but rather annoying bug because it means that when appending the output of csvq --format CSV --without-header of a CSV file that contains no rows to another CSV file, csvq appends a blank line.

mithrandie commented 4 years ago

The behavior is intended, but you are probably right. Please wait a while, I’ll check about there is no problem if output nothing when there is no data to be output.

ondohotola commented 4 years ago

I use something like

sed '/^$/d'

as a filter :-)-O

el

On 12/12/2019 09:18, Yuki wrote:

The behavior is intended, but you are probably right. Please wait a while, I’ll check about there is no problem if output nothing when there is no data to be output.

-- Dr. Eberhard W. Lisse \ / Obstetrician & Gynaecologist el@lisse.NA / * | Telephone: +264 81 124 6733 (cell) PO Box 8421 \ / Bachbrecht 10007, Namibia ;____/

derekmahar commented 4 years ago

Yes, I agree that | sed '/^$/' is a workaround, but users would first need to identify csvq --format CSV --without-header as the source of the blank line and then apply this filter to every instance.

On Thu., Dec. 12, 2019, 2:24 a.m. ondohotola, notifications@github.com wrote:

I use something like

sed '/^$/d'

as a filter :-)-O

el

mithrandie commented 4 years ago

Fixed and released as the version 1.11.8. Thanks.

derekmahar commented 4 years ago

Thank you! The blank line is gone!

$ printf "date,source_currency_code,target_currency_code,exchange_rate" |
  csvq --format CSV --without-header "SELECT * FROM STDIN"
$