Deleting a subdirectory in the path of a URL via sed or perl #

Delete the divers subdirs which appear between "/blog/" and the filenames in this example:

$ cat index.rss
...
    <link>https://tinyapps.org/blog</link>
...
      <link>https://tinyapps.org/blog/misc/202009080700_usbimager.html</link>
...
      <link>https://tinyapps.org/blog/mac/202009070700_2011_mac_mini_snow_leopard.html</link>
...
      <link>https://tinyapps.org/blog/windows/202008200700_vostro_2420_lines.html</link>
...

with GNU sed:

$ sed -i -E 's (tinyapps.org/blog)/[a-z]+ \1 ' index.rss

or Perl:

$ perl -pi -e 's|(tinyapps.org/blog)/[a-z]+|\1|' index.rss

/nix | Sep 13, 2020


Subscribe or visit the archives.