title: Unable to make the mentioned regular expression to work in sed command
body: <p>I am trying to make the following regular expressions to work in <code>sed</code> command in bash.</p>
  <pre><code>^[^&lt;]?(https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&amp;\/\/=]*))[^&gt;]?$
  </code></pre>
  <p>I know the regular expression is correct and it is working as I expected. So; there is no help needed with that. I tested it on online regular expressions tester and it is working as per my expectations.</p>
  <p>Please find the demo of the above regex in <a href="https://regex101.com/r/Ly1N3T/2" rel="nofollow noreferrer"><strong>here.</strong></a></p>
  <p><strong>My requirement:</strong>
  I want to enclose every url inside <code>&lt;&gt;</code>. If the url is already enclosed; then append it to the result as can be seen in the above regex link.</p>
  <p><strong>Sample Input:(in file named website.txt)</strong></p>
  <pre><code>// List of all legal urls
  https://www.google.com/
  https://www.fakesite.co.in
  https://www.fakesite.co.uk
  &lt;https://www.fakesite.co.uk&gt;
  &lt;https://www.google.com/&gt;
  </code></pre>
  <p><strong>Expected Output:(in the file named output.txt)</strong></p>
  <pre><code>&lt;https://www.google.com/&gt; // Please notice every url is enclosed in the &lt;&gt;.
  &lt;https://www.fakesite.co.in&gt;
  &lt;https://www.fakesite.co.uk&gt;
  &lt;https://www.fakesite.co.uk&gt; // Please notice if the url is already enclosed in &lt;&gt; then it is appended as it is.
  &lt;https://www.google.com/&gt;
  </code></pre>
  <p><strong>What I tried in sed:</strong></p>
  <ol>
  <li><p>Since I'm not well-versed in bash commands; so previously I was not able to capture the group properly in <code>sed</code> but after reading <a href="https://unix.stackexchange.com/questions/263668/sed-capture-groups-not-working"><strong>this</strong></a> answer; I figured out that we need to escape the parenthesis to be able to capture it.</p>
  </li>
  <li><p>Somewhere; I read that look-arounds are not supported in <code>sed</code>(GNU based) so I removed lookarounds too; but that also didn't worked. <strong>If it doesn't support look-arounds then I used <a href="https://regex101.com/r/Ly1N3T/1" rel="nofollow noreferrer"><strong>this</strong></a> regex and it served my purpose.</strong></p>
  </li>
  <li><p>Then; this is my latest try with <code>sed</code> command:</p>
  <pre><code>sed 's@^[^&lt;]?(https?://(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&amp;/=]*))[^&gt;]?$@&lt;\1&gt;@gm;t;d' websites.txt &gt; output.txt
  </code></pre>
  </li>
  </ol>
  <p><strong>My exact problem:</strong></p>
  <p>How can I make the above command to work properly. If  you'll run the command sample I attached above in point-3; you'd see it is not replacing the contents properly. It is just dumping the contents of <code>websites.txt</code> to <code>output.txt</code>. But in regex demo; attached above it is working properly i.e. enclosing all the unenclosed websites inside <code>&lt;&gt;</code>. Any suggestions would be helpful. <strong>I preferably want it in sed but if it is possible can I convert the above command in awk also</strong>? If you can please help me with that too; I'll be highly obliged. Thanks</p>