Coder Social home page Coder Social logo

replace into a new column about gocsv HOT 4 CLOSED

aotimme avatar aotimme commented on August 16, 2024
replace into a new column

from gocsv.

Comments (4)

aotimme avatar aotimme commented on August 16, 2024

To do this I will often add a select beforehand to duplicate the column and then run a replace on the duplicated column.

e.g. if my CSV just has two columns and I want to replace something in the second column and store that in a third column with a new name ("Name" here), I might do

cat myfile.csv | gocsv select -c 1,2,2 | gocsv replace -c 3 --regex "Hello, (.*)\!" --repl "\$1" | gocsv rename -c 3 --names Name

I'm not opposed to adding a feature to copy the replaced column into a new column, but I'm not sure what the optimal set of flags should look like for that option.

Do you have any suggestions on how it should look? Would you expect the new column to have the same header name or would you want to be able to specify the header for the new column?

from gocsv.

bsutton avatar bsutton commented on August 16, 2024

Yes I've been playing and found the select syntax to duplicate columns.
I hadn't noticed the rename and combining the select and rename clearly works but maybe something like this would be more obvious

gocsv copy -c "ContactName" -name "NewContactName"

The copied field would be appended to the csv row.

from gocsv.

bsutton avatar bsutton commented on August 16, 2024

btw: nice tool, saved me hours, so thanks!

from gocsv.

aotimme avatar aotimme commented on August 16, 2024

I think the add subcommand along with the addition of sprig (#28) should handle this case really well now. I'm going to close this.

from gocsv.

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.