csvkit icon indicating copy to clipboard operation
csvkit copied to clipboard

csvsed (or csvgrep with replace)

Open geekscrapy opened this issue 5 years ago • 5 comments

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!

geekscrapy avatar Jan 14 '20 06:01 geekscrapy

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!

jpmckinney avatar Feb 03 '20 22:02 jpmckinney

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

geekscrapy avatar Feb 04 '20 00:02 geekscrapy

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 avatar Feb 04 '20 15:02 jpmckinney

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

jpmckinney avatar Apr 30 '24 18:04 jpmckinney

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 avatar May 02 '24 17:05 jpmckinney