我正在尝试从 csv 文件的第 31 列中删除第一个值。这些列用引号括起来,并用逗号分隔,就像这样。
"first_name","last_name","home_address"
"Frank",Russel","123 Hampton road"
第 31 列是图像列,图像用逗号分隔
"http://ddd.com/124dfr3f.jpg,http://ddd.com/hjasgx37trg.jpg"
必须从第 31 列中删除第一个图像和尾部逗号
添加- 这是一个示例。
"one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","three","four","five","six","seven","eight","nine","ten","twenty-one","twenty-two","three","four","five","six","seven","eight","nine","ten","thirty-one","thirty-two","three","four","five","six","seven","eight","nine","forty"
"one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","three","four","five","six","seven","eight","nine","ten","twenty-one","twenty-two","three","four","five","six","seven","eight","nine","http://pictures.domain.com/e/josequervo/1183/eeeffcc7927sssssssssss5d26c0eb19e1dc53548x.jpg","http://pictures.domain.com/e/josequervo/0083/eeef8cc7927bf1245d26c0eb19e1dc53545x.jpg,http://pictures.domain.com/e/josequervo/0099/eeefscc7927bf1245d26c0eb19e1dc53546x.jpg,http://pictures.domain.com/e/josequervo/0012/eeefdcc7927bf1245d26c0eb19e1dc53547x.jpg,http://pictures.domain.com/e/josequervo/1183/eeeffcc7927bf1245d26c0eb19e1dc53548x.jpg,http://pictures.domain.com/e/josequervo/1234/eeefgcc7927bf1245d26c0eb19e1dc53549x.jpg,http://pictures.domain.com/e/josequervo/asee/eeefhcc7927bf1245d26c0eb19e1dc53540x.jpg,http://pictures.domain.com/e/josequervo/2341/eeefjcc7927bf1245d26c0eb19e1dc53544x.jpg","two",three","four","five","six","seven","eight","nine","forty"
此网址和逗号必须删除
http://pictures.domain.com/e/josequervo/0083/eeef8cc7927bf1245d26c0eb19e1dc53545x.jpg,
我只发布了 csv 文件的前 2 行,但该文件是 300 - 400 行,并且必须从第 2 行删除该图像到最后一行。我们不能改变第一行。
使用 GNU
sed
,我们可以这样处理:可以理解为:
","
在当前行中字符串的第 30 次出现处放置一个占位符。然后,从占位符一直到第一个逗号,我们一路删除所有内容。
其他方法如下:
方法:
perl 将逐行读取 csv 文件,并且对于每一行,它将围绕字符串
","
拆分并将拆分元素存储在数组 @F 中。然后对于第 31 个元素,我们删除直到第一个逗号的所有内容。
根据您的问题,第 31 列中存在以逗号分隔的图像,我们需要从第 31 列中删除第一个字符
经过测试并且工作正常让我们知道任何混淆