Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

csvsed (or csvgrep with replace) #1057

Open
geekscrapy opened this issue Jan 14, 2020 · 5 comments
Open

csvsed (or csvgrep with replace) #1057

geekscrapy opened this issue Jan 14, 2020 · 5 comments

Comments

@geekscrapy
Copy link

An idea, have a sed like module within csvkit. This would allow grepping based on columns, and also (more importantly) replacing values in certain columns based on regex.

Must haves:

  • Ability to find lines matching the regex (for testing, appreciate this overlaps with csvgrep)
  • Ability to replace the found regex

Nice to haves:

  • User can provide a list of regex replacements by file
  • Ability to use replacement groups

I may have a use-case for this in the near future but logging it here incase someone thinks its needed and wants to take a crack before me!

@jpmckinney
Copy link
Member

Hi @geekscrapy, to keep the maintenance burden reasonable, we aren't adding new tools to csvkit. That said, people can certainly create their own Python packages to offer new CSV tools!

@geekscrapy
Copy link
Author

Many thanks, I'll probably be looking into this in the next few months so may have a pull request coming 👍

@jpmckinney
Copy link
Member

I just remembered: have a look at https://github.com/johnkerl/miller, which I think has the feature you're looking for (miller put).

@jpmckinney
Copy link
Member

Just a note that csvsql can be used to query and modify CSV files, see e.g. #1243

@jpmckinney jpmckinney changed the title Proposal: csvsub csvsed (or csvgrep with replace) May 2, 2024
@jpmckinney
Copy link
Member

jpmckinney commented May 2, 2024

csvmedkit has a csvsed command, which might not be too much effort to add as an option to csvgrep: https://github.com/dannguyen/csvmedkit/blob/main/csvmedkit/utils/csvsed.py Can also look at https://pypi.org/project/csvsed/

That said, see comments in #268. Also, qsv already has a replace command.

This can maybe be used to resolve #396 (#530 #814)

@jpmckinney jpmckinney reopened this May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants