jeroenjanssens / data-science-at-the-command-line

Data Science at the Command Line
https://datascienceatthecommandline.com
Other
3.8k stars 764 forks source link

Not able to use cols with sed #50

Closed aborruso closed 8 years ago

aborruso commented 8 years ago

Hi, I have this CSV (input_out.csv):

nome,id,url,start,creato,venue_id,logo
Palermo (Sicilia) - 25 Maggio 2016 25/5/2016 Karaoke di beneficenza di Chi ama la Sicilia,25180566753,http://www.eventbrite.it/e/biglietti-palermo-sicilia-25-maggio-2016-2552016-karaoke-di-beneficenza-di-chi-ama-la-sicilia-25180566753?aff=ebapi,2016-05-25T20:00:00,2016-05-03T20:40:12Z,15149091,https://img.evbuc.com/https%3A%2F%2Fimg.evbuc.com%2Fhttp%253A%252F%252Fcdn.evbuc.com%252Fimages%252F20814649%252F175077385541%252F1%252Foriginal.jpg%3Frect%3D0%252C172%252C860%252C430%26s%3Dd9a4bfa29cc27f85d8428de320cc9b3c?h=200&w=450&s=7ed859da13004f17403a9a3b0e1b2f7b
Tech-Marketplace & StartupItalia! Open Summit Tour 2016,25161107550,http://www.eventbrite.it/e/biglietti-tech-marketplace-startupitalia-open-summit-tour-2016-25161107550?aff=ebapi,2016-05-17T15:00:00,2016-05-03T10:49:31Z,15134493,https://img.evbuc.com/https%3A%2F%2Fimg.evbuc.com%2Fhttp%253A%252F%252Fcdn.evbuc.com%252Fimages%252F20794591%252F68137449621%252F1%252Foriginal.jpg%3Frect%3D473%252C0%252C3674%252C1837%26s%3De156d1a692274f2b3e48fa61b9e3964d?h=200&w=450&s=cfa6f9b49d4dee5180e53c71931a167d

I would like to replace the & characther that I have in the first column with &.

If I write:

cat input_out.csv | sed -e 's/[\/&]/test/g' > out.txt

I have what I want. But I would like to work only in the first column. But if I write:

< input_out.csv cols -c nome body sed -e 's/[\/&]/test/g' > out.txt

I have

sed: -e expression #1, char 4: unterminated `s' command

What's wrong in my command?

Thank you

jeroenjanssens commented 8 years ago

I think the issue is that "&" is a special character. Perhaps somewhere in cols or body not everything is quoted properly. As a stop-gap solution, I suggest you put the sed command into a separate script:

< input_out.csv cols -c nome body ./replace.sh

Then it works. Good luck.

aborruso commented 8 years ago

@jeroenjanssens is it useful that I create a new issue related to cols or body and this small problem with quoting?

Thank you