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

Question: parsing text column-wise #1243

Closed
kiteloopdesign opened this issue Apr 30, 2024 · 4 comments
Closed

Question: parsing text column-wise #1243

kiteloopdesign opened this issue Apr 30, 2024 · 4 comments
Labels

Comments

@kiteloopdesign
Copy link

kiteloopdesign commented Apr 30, 2024

Hi,
please allow me to ask a question although I do not think this is possible with the current set of csv utilities. Is it possible to parse some string column wise? For instance, this csv

col1, col2, col3
str1, str2-remove, str3

csvparse -c 2 --regexp 's/str2-remove/str2/'

col1, col2, col3
str1, str2, str3

Thanks

@jpmckinney
Copy link
Member

No - that tool was requested here, but csvkit is not adding new tools: #1057

That said you can use e.g.

printf 'col1, col2, col3\nstr1, str2-remove, str3' | csvsql --query "SELECT col1, REPLACE(\" col2\", '-remove', '') AS \" col2\", \" col3\" FROM stdin"

The weird quoting is because your CSV for some reason has spaces at the start of each cell.

@jpmckinney jpmckinney closed this as not planned Won't fix, can't repro, duplicate, stale Apr 30, 2024
@kiteloopdesign
Copy link
Author

Thanks a lot for your quick reply and for the amazing toolset!

@jpmckinney
Copy link
Member

Btw, the unmaintained csvmedkit package has a "csvsed" command. I haven't tried it: https://pypi.org/project/csvmedkit/

@jpmckinney
Copy link
Member

I've reopened #1057 for consideration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants