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
-i= edit file in place
-E= use Extended regular expressions in the script
s= substitute the replacement string for the first instance of the regular expression in the pattern space. (Where are the forward slashes ("/") you ask? Replaced with whitespace! since sed accepts any single-byte character as a delimiter.)
(tinyapps.org/blog)= capture group (or, as the GNU sed documentation has it, subexpression)
/[a-z]+= a forward slash followed by one or more lower case letters
\1= back-reference referring to the subexpression above
perl -pi -e 's|(tinyapps.org/blog)/[a-z]+|\1|' index.rss
-p= print lines (more precise explanation)
-i= edit in-place
-e= enter one line of program
/nix | Sep 13, 2020
Subscribe or visit the archives.