Regex sed替换文本并放在行尾

Regex sed替换文本并放在行尾,regex,sed,Regex,Sed,获取以下输出: <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.j

获取以下输出:

<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|
这不雅观。我将寻找另一个解决方案。我需要知道如何保存目录URL并将每个URL放在行尾
http://img9.domain.xy/t/929/320/


thx帮助

如果您想要url的最后一部分,如“”,可以使用以下正则表达式:
/([0-9\+\.[a-z]{3,4}+)


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

hmm当我键入命令sed的|/([0-9|]+\.[a-z]{3,4}+)| | g'thx时,输出是这样的。好的,我们用while来读取文件的每一行。grep-oE获取url模式,uniq删除重复项。这就是var$行的全部内容。使用第一个sed命令,我们只得到jpg文件名。但是我们在这里做什么呢?“s.*.&“${var}”g.@Malik
&
打印与
sed管道
左侧相同的内容(本例中为
*
),然后在其后添加“$var”,意思是到末尾。
<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/
sed 's|http://img*......................||g'
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;
<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/