Comments (4)
Seconding the request this insert
ability, and expanding on the use case for insert row
. Something I currently do occasionally with jq
is use it to generate properly-formatted JSON; I would love to be able to do something similar for CSV with the guarantee of all the quoting and escaping.
For example, with jq
, I might do:
JSON_TEMPLATE='{$filePath, $size, $mtime}'
JSON=$(
jq -n -c\
--arg 'filePath' "$PATH" \
--arg 'size' "${SIZE}" \
--arg 'mtime' "${MTIME}" \
"$JSON_TEMPLATE"
)
to generate a line like {"filePath": "...", "size": "...", "mtime": "..."}
Going off of the syntax suggested by the OP, this could be something like:
xsv insert row filePath:"$PATH" size:"$SIZE" mtime:"$MTIME" > file.csv
or even something lower-level, like
xsv format "$PATH" "$SIZE" "$MTIME" >> file.csv
to allow for specifying various options (delimiter, line endings, column types, etc).
I'd be okay hearing that this is out of scope for this project, but it feels like it would be nice to have in a CLI "toolkit"
from xsv.
Not as convenient and requires an extra file, but this is already possible with a cross join:
cat > table.csv <<EOF
a,b
1,2
2,4
EOF
# file for fixed column
cat > fixed.csv << EOF
c
FIXED
EOF
# add the column to table.csv
xsv join --cross 1 table.csv 1 fixed.csv
This results in the following output:
a,b,c
1,2,FIXED
2,4,FIXED
from xsv.
I can see how this might be occasionally useful.
from xsv.
I need this today
from xsv.
Related Issues (20)
- Escaping unescaped quotes in quoted strings modifies the data HOT 2
- support unbalanced partitioning HOT 1
- sample the whole file HOT 1
- bug: xsv count HOT 3
- Frequency command causes allocated memory exhausted message on csv file with many fields
- Add Parquet support
- fixlengths is missing the field delimiter option for output (-t)
- what format is accepted for non printable delimiter?
- support flexible format csv
- Escape square bracket in column header? HOT 1
- xsv table displays values with escaped `"`s incorrectly HOT 7
- `sample` command with alternative delimiter: Could not deserialize to u64 for '<sample-size>'. HOT 2
- `xsv join --cross` shouldn't require columns to match HOT 1
- crc32 a column's values?
- sort by mixed column types, some numeric and some non-numeric, some forward and some reverse
- Looking for a solution to clear column data but not the headers HOT 1
- Flexible input options for quote and escape in `fixlengths`
- `xsv table` has unexpected output with long input (too-wide tabs, missing tabs) HOT 3
- set delimiter config before parsed by xsv HOT 3
- Just want to say thank you HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xsv.