我有一个包含URI的列表,如下所示:
./journal.html
./john-voigt.html
./flower_power28182.html
现在我想正则表达式文件(选择一个:sed/awk/php),以便结果如下所示:
<a href="http://domain.com/journal.html">http://domain.com/journal.html</a><br>
<a href="http://domain.com/john-voigt.html">http://domain.com/john-voigt.html</a><br>
<a href="http://domain.com/flower_power28182.html">http://domain.com/flower_power28182.html</a><br>
可做的?
s/^'.(.*)$/<a href="http:'/'/domain.com$1">http:'/'/domain.com$1<'/a><br>/
对于sed...
sed s_^'.'(.*')$_<a' href="http://domain.com'1">http://domain.com'1</a><br>_
你为什么不这样做:
$Array = array( './journal.html',
'./john-voigt.html',
'./flower_power28182.html');
foreach($Array as $Key => $Link){
$Link = str_replace('./', '', $Link);
$Array[$Key] = '<a href="http://domain.com/'.$Link.'">http://domain.com/'.$Link.'</a>';
}
AWK:
awk 'BEGIN {url = "http://domain.com"} {sub(/'./, url); print "<a href='"" $0 "'">" $0 "</a><br>"}'