从 csv 文件中剥离单数 /
我有一个 csv 文件,其中有一些区域 / 没有任何内容,并且没有任何我想删除的内容。问题是,文件中还有其他项目,其中有一个我不想删除的 / 。
举个例子:
/abc, /, akaksdhfaiwe
/, /foo, /bar
我想:
/abc,, akaksdhfaiwe
, /foo, /bar
我该怎么做?我不能使用 gsub('^/', '') 因为它会删除 /abc /foo /bar。在我的一生中,我似乎找不到“结束”。我希望 \Z 能起作用,但没有运气。
有接受者吗?
我一直在使用 fastCSV 进行大量操作,到目前为止效果非常好。
I have a csv file which has a few areas where / proceeded by nothing and proceeded by nothing that I'd like to strip out. The catch is, I also have other items in the file which have a / that I don't want to strip out.
an example:
/abc, /, akaksdhfaiwe
/, /foo, /bar
I'd like to be:
/abc,, akaksdhfaiwe
, /foo, /bar
How do I do this? I can't use gsub('^/', '') because it would strip out the /abc /foo /bar. And for the life of me, I can't seem to find an 'ends with'. I was hoping that \Z would work, no luck.
Any takers?
I've been using fasterCSV for a lot of the manipulation which has been pretty great so far.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果你的文件不是那么大,那么你可以在清理它的同时将其放入内存中,然后再次将其写出:
如果你不知何故有一个非常大的 CSV 文件,无法一次全部放入内存:
要么应该把这个:
进入
If your file isn't that big then you could slurp it into memory while cleaning it up and then write it out again:
If you somehow have an incredibly massive CSV file that won't fit in memory all at once:
Either should turn this:
into
使用红宝石你可以这样做:
With ruby you can do: