加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则表达式 – 使用加号前置文件名

发布时间:2020-12-14 06:24:54 所属栏目:百科 来源:网络整理
导读:我想在一个巨大的文件中使用sed在所有出现的图像名称之前添加一个(加号). 这是一行的示例: DAUSSI-H22-14K White Gold-Princess-1.00ct-G-SI1orH-VS2-EGL-mm-3.5,H22,7050,5720,3/5/2012 7:34,1,henri-daussi-h22-diamond-halo-engagement-ring-14k-white-g
我想在一个巨大的文件中使用sed在所有出现的图像名称之前添加一个(加号).

这是一行的示例:

DAUSSI-H22-14K White Gold-Princess-1.00ct-G-SI1orH-VS2-EGL-mm-3.5,H22,7050,5720,3/5/2012 7:34,1,henri-daussi-h22-diamond-halo-engagement-ring-14k-white-gold-width--mm-style-princess-1-00ct-g-si1-or-h-vs2-egl-size-3-5,henri-daussi-h22-diamond-halo-engagement-ring-14k-white-gold-width--mm-style-princess-1-00ct-g-si1-or-h-vs2-egl-size-3-5.html,Henri Daussi H22 Diamond Halo Engagement Ring-14K White Gold-Style:Princess-1.00ct-G-SI1 or H-VS2-EGL-Width: mm-Size:3.5,"Henri Daussi engagement ring with hand-matched side diamonds in a beautiful halo setting,totaling 1.40 carats. The image at left displays this ring with a 1.00 carat princess cut diamond. This setting can accommodate a variety of shapes and sizes. Please contact us on the range of possibilities of any ring.",14K White Gold,Princess-1.00ct-G-SI1 or H-VS2-EGL,3.5,Metal_Style_Width_Size,simple,/H22.jpg,Shown with a 1.00 carat princess cut diamond.,/H_22.jpg,Enabled,Taxable Goods,Not Visible Individually,No,Engagement Rings/Henri Daussi;;Designers/Henri Daussi,"ROUND,PEAR SHAPE,EMERALD CUT,MARQUISE,OVAL,RADIANT,PRINCESS CUT,HEART SHAPE,CUSHION CUT,ASSCHER CUT",.45-6.00 Carat,/H22.jpg

对于这一行,图像是/H22.jpg,我想将此字符串更改为/H22.jpg.

据我所知,所有图像都以/开头,但它是一个巨大的文件,我不能完全确定.我确定的一件事是之前有一个逗号(它是逗号分隔的.csv文件).所以我需要用[image_name] .extension替换[除dot之外的任何字符] [dot](.jpg | .gif | .png).

这是迄今为止我做过的最好的事情:

sed -ie 's/,([a-zA-Z0-9/_]+)(.jpg|.png|.gif)/,+12/g' file.csv

但它不起作用.

试试这个:
sed 's#(,)([^.,]+.(jpg|png|gif))#1+2#g' infile

说明:

s#...#...#g             # Substitute command. '#' is separator and 'g' is to apply it many times for 
                        # each line.
(,)                   # Match a comma,and save it as '1'
[^.,]+.               # Match any characters until a '.' or ',' found.
(jpg|png|gif)       # Match extension.
1+2                   # Replace with: Comma,plus sign and the image name.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读