Giter Club home page Giter Club logo

Comments (4)

junoatwork avatar junoatwork commented on August 16, 2024 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.

opax avatar opax commented on August 16, 2024 3

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.

BurntSushi avatar BurntSushi commented on August 16, 2024

I can see how this might be occasionally useful.

from xsv.

dysinger avatar dysinger commented on August 16, 2024

I need this today

from xsv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.