Issue
I have a file:
<a href="http://www.gnu.org/software/coreutils/">http://www.gnu.org/software/coreutils/</a>
<a href="../../3/glob.html" rel="nofollow">glob</a>
<a href="lxc-ls.html" rel="nofollow">lxc-ls</a>
I need to only replace below:
<a href="lxc-ls.html" rel="nofollow">lxc-ls</a>
with
<a href="../lxc-ls.html" rel="nofollow">lxc-ls</a>
lxc-ls can be any word as I have multiple such links in several files which I need to replace.
I do not want to make any changes to the other 2 links. i.e.
<a href="http://www.gnu.org/software/coreutils/">http://www.gnu.org/software/coreutils/</a>
<a href="../../3/glob.html" rel="nofollow">glob</a>
What I have tried until is:
$ sed '/html/ i\
..' file
But this appends to the start of the line, also the other condition of excluding 2 URLs is also not full filled.
Here is a more realistic example from one of the file.
<b><a href="../../1/echoping.html" rel="nofollow">echoping</a></b>(1),
<b><a href="../../3/getaddrinfo.html" rel="nofollow">getaddrinfo</a></b>(3),
<b><a href="../../3/getaddrinfo_a.html" rel="nofollow">getaddrinfo_a</a></b>(3),
<b><a href="../../2/getpeername.html" rel="nofollow">getpeername</a></b>(2),
<b><a href="../../2/getsockname.html" rel="nofollow">getsockname</a></b>(2),
<b><a href="../../3/ping_setopt.html" rel="nofollow">ping_setopt</a></b>(3),
<b><a href="../../5/proc.html" rel="nofollow">proc</a></b>(5),
<b><a href="rds.html" rel="nofollow">rds</a></b>(7),
<b><a href="../../2/recv.html" rel="nofollow">recv</a></b>(2),
<b><a href="rtnetlink.html" rel="nofollow">rtnetlink</a></b>(7),
<b><a href="sctp.html" rel="nofollow">sctp</a></b>(7),
<b><a href="../../3/sctp_connectx.html" rel="nofollow">sctp_connectx</a></b>(3),
<b><a href="../../2/send.html" rel="nofollow">send</a></b>(2),
<b><a href="udplite.html" rel="nofollow">udplite</a></b>(7)
<a href="http://gnu.org/licenses/gpl.html">http://gnu.org/licenses/gpl.html</a>
<a href="http://translationproject.org/team/">http://translationproject.org/team/</a>
Here I only need to replace:
<b><a href="rds.html" rel="nofollow">rds</a></b>(7),
<b><a href="rtnetlink.html" rel="nofollow">rtnetlink</a></b>(7),
<b><a href="sctp.html" rel="nofollow">sctp</a></b>(7),
<b><a href="udplite.html" rel="nofollow">udplite</a></b>(7)
with:
<b><a href="../rds.html" rel="nofollow">rds</a></b>(7),
<b><a href="../rtnetlink.html" rel="nofollow">rtnetlink</a></b>(7),
<b><a href="../sctp.html" rel="nofollow">sctp</a></b>(7),
<b><a href="../udplite.html" rel="nofollow">udplite</a></b>(7)
Solution
Using sed
$ sed s'|"\([[:alpha:]].*\)|"../\1|' file
<b><a href="../../1/echoping.html" rel="../nofollow">echoping</a></b>(1),
<b><a href="../../3/getaddrinfo.html" rel="../nofollow">getaddrinfo</a></b>(3),
<b><a href="../../3/getaddrinfo_a.html" rel="../nofollow">getaddrinfo_a</a></b>(3),
<b><a href="../../2/getpeername.html" rel="../nofollow">getpeername</a></b>(2),
<b><a href="../../2/getsockname.html" rel="../nofollow">getsockname</a></b>(2),
<b><a href="../../3/ping_setopt.html" rel="../nofollow">ping_setopt</a></b>(3),
<b><a href="../../5/proc.html" rel="../nofollow">proc</a></b>(5),
<b><a href="../rds.html" rel="nofollow">rds</a></b>(7),
<b><a href="../../2/recv.html" rel="../nofollow">recv</a></b>(2),
<b><a href="../rtnetlink.html" rel="nofollow">rtnetlink</a></b>(7),
<b><a href="../sctp.html" rel="nofollow">sctp</a></b>(7),
<b><a href="../../3/sctp_connectx.html" rel="../nofollow">sctp_connectx</a></b>(3),
<b><a href="../../2/send.html" rel="../nofollow">send</a></b>(2),
<b><a href="../udplite.html" rel="nofollow">udplite</a></b>(7)
Answered By - HatLess Answer Checked By - Cary Denson (WPSolving Admin)