我有一个巨大的文件列表,我想添加到灯箱galery。我生成了缩略图,我只需要让sed抓住从“foto”到“bmp”“jpeg”或“jpg”或“png”的所有内容(我的一些图像的扩展名已锁定,如PNG,JPG JPEG BMP)并在扩展名前加-thumb
添加到该行的末尾。
制作本
<a href="images/foto (1000).jpeg" rel="lightbox[galeria]" title="Description."><img src="images/
<a href="images/foto (950).bmp" rel="lightbox[galeria]" title="Description."><img src="images/
<a href="images/foto (10).png" rel="lightbox[galeria]" title="Description."><img src="images/
<a href="images/foto (100).JPG" rel="lightbox[galeria]" title="Description."><img src="images/
看起来像这样
<a href="images/foto (1000).jpeg" rel="lightbox[galeria]" title="Description."><img src="images/foto (1000)-thumb.jpeg
<a href="images/foto (950).bmp" rel="lightbox[galeria]" title="Description."><img src="images/foto (950)-thumb.bmp
<a href="images/foto (10).png" rel="lightbox[galeria]" title="Description."><img src="images/foto (10)-thumb.png
<a href="images/foto (100).JPG" rel="lightbox[galeria]" title="Description."><img src="images/foto (100)-thumb.JPG
我已经能够在模式之间进行处理,并在行尾添加内容,但我无法完成这项工作。
答案 0 :(得分:1)
这可能对你想要的东西太脏了,但这是使用GNU awk
的一种方式:
awk -F '["./]' '{ print $0 $3 "-thumbs." $4 }' file.txt
结果:
<a href="images/foto (1000).jpeg" rel="lightbox[galeria]" title="Description."><img src="images/foto (1000)-thumbs.jpeg
<a href="images/foto (950).bmp" rel="lightbox[galeria]" title="Description."><img src="images/foto (950)-thumbs.bmp
<a href="images/foto (10).png" rel="lightbox[galeria]" title="Description."><img src="images/foto (10)-thumbs.png
<a href="images/foto (100).JPG" rel="lightbox[galeria]" title="Description."><img src="images/foto (100)-thumbs.JPG