1

得到以下输出:

<iframe  src="http://domain.xy/load.php?file=2260301" frameborder="0" scrolling="no"></iframe>|http://img1.domain.xy/t/301/320/5_2260301.jpg;http://img1.domain.xy/t/301/320/1_2260301.jpg;http://img1.domain.xy/t/301/320/2_2260301.jpg;http://img1.domain.xy/t/301/320/3_2260301.jpg;http://img1.domain.xy/t/301/320/4_2260301.jpg;http://img1.domain.xy/t/301/320/6_2260301.jpg;http://img1.domain.xy/t/301/320/7_2260301.jpg;http://img1.domain.xy/t/301/320/8_2260301.jpg;http://img1.domain.xy/t/301/320/9_2260301.jpg;http://img1.domain.xy/t/301/320/10_2260301.jpg|
<iframe  src="http://domain.xy/load.php?file=2260279" frameborder="0" scrolling="no"></iframe>|http://img9.domain.xy/t/279/320/10_2260279.jpg;http://img9.domain.xy/t/279/320/1_2260279.jpg;http://img9.domain.xy/t/279/320/2_2260279.jpg;http://img9.domain.xy/t/279/320/3_2260279.jpg;http://img9.domain.xy/t/279/320/4_2260279.jpg;http://img9.domain.xy/t/279/320/5_2260279.jpg;http://img9.domain.xy/t/279/320/6_2260279.jpg;http://img9.domain.xy/t/279/320/7_2260279.jpg;http://img9.domain.xy/t/279/320/8_2260279.jpg;http://img9.domain.xy/t/279/320/9_2260279.jpg|
<iframe  src="http://domain.xy/load.php?file=2259929" frameborder="0" scrolling="no"></iframe>|http://img9.domain.xy/t/929/320/1_2259929.jpg;http://img9.domain.xy/t/929/320/2_2259929.jpg;http://img9.domain.xy/t/929/320/3_2259929.jpg;http://img9.domain.xy/t/929/320/4_2259929.jpg;http://img9.domain.xy/t/929/320/5_2259929.jpg;http://img9.domain.xy/t/929/320/6_2259929.jpg;http://img9.domain.xy/t/929/320/7_2259929.jpg;http://img9.domain.xy/t/929/320/8_2259929.jpg;http://img9.domain.xy/t/929/320/9_2259929.jpg;http://img9.domain.xy/t/929/320/10_2259929.jpg|

并需要以下内容:

<iframe  src="http://domain.xy/load.php?file=2260301" frameborder="0" scrolling="no"></iframe>|5_2260301.jpg;1_2260301.jpg;2_2260301.jpg;3_2260301.jpg;4_2260301.jpg;6_2260301.jpg;7_2260301.jpg;8_2260301.jpg;9_2260301.jpg;10_2260301.jpg|http://img1.domain.xy/t/301/320/|
<iframe  src="http://domain.xy/load.php?file=2260279" frameborder="0" scrolling="no"></iframe>|10_2260279.jpg;1_2260279.jpg;2_2260279.jpg;3_2260279.jpg;4_2260279.jpg;5_2260279.jpg;6_2260279.jpg;7_2260279.jpg;8_2260279.jpg;9_2260279.jpg|http://img9.domain.xy/t/279/320/|
<iframe  src="http://domain.xy/load.php?file=2259929" frameborder="0" scrolling="no"></iframe>|1_2259929.jpg;2_2259929.jpg;3_2259929.jpg;4_2259929.jpg;5_2259929.jpg;6_2259929.jpg;7_2259929.jpg;8_2259929.jpg;9_2259929.jpg;10_2259929.jpg|http://img9.domain.xy/t/929/320/

我使用此命令仅获取 jpg 文件名,

sed 's|http://img*......................||g'

这不优雅。我将寻找另一个解决方案。我需要知道如何保存目录 url 并将每个放在行尾http://img9.domain.xy/t/929/320/

谢谢帮助

4

2 回答 2

0

如果你想要 URL 的最后一部分,比如“ http://img1.domain.xy/t/301/320/5_2260301.jpg ”,你可以使用这个正则表达式:/([0-9_]+\.[a-z]{3,4}+)

适用于所有数字和所有扩展名(.jpeg、.png、...)

于 2013-10-02T19:11:54.160 回答
0
while IFS= read -r line; 
do 
  var=$(echo "$line" | grep -oE "http://img[0-9].domain.xy/t/[0-9][0-9][0-9]/[0-9][0-9][0-9]/" | uniq); 
  echo "$line" | sed -e 's|http://img[0-9].domain.xy/t/[0-9][0-9][0-9]/[0-9][0-9][0-9]/||g' -e "s|.*|&"${var}"|g" >> newFile; 
done < file;

读取文件的每一行,while然后grep使用 pattern http://img...,将其放入一个变量中,使用sedcut 该模式并将变量放在行尾。

结果被写入一个新文件:

<iframe  src="http://domain.xy/load.php?file=2260301" frameborder="0" scrolling="no"></iframe>|5_2260301.jpg;1_2260301.jpg;2_2260301.jpg;3_2260301.jpg;4_2260301.jpg;6_2260301.jpg;7_2260301.jpg;8_2260301.jpg;9_2260301.jpg;10_2260301.jpg|http://img1.domain.xy/t/301/320/
<iframe  src="http://domain.xy/load.php?file=2260279" frameborder="0" scrolling="no"></iframe>|10_2260279.jpg;1_2260279.jpg;2_2260279.jpg;3_2260279.jpg;4_2260279.jpg;5_2260279.jpg;6_2260279.jpg;7_2260279.jpg;8_2260279.jpg;9_2260279.jpg|http://img9.domain.xy/t/279/320/
<iframe  src="http://domain.xy/load.php?file=2259929" frameborder="0" scrolling="no"></iframe>|1_2259929.jpg;2_2259929.jpg;3_2259929.jpg;4_2259929.jpg;5_2259929.jpg;6_2259929.jpg;7_2259929.jpg;8_2259929.jpg;9_2259929.jpg;10_2259929.jpg|http://img9.domain.xy/t/929/320/
于 2013-10-02T19:26:18.523 回答