Using sed I’m having a problem trying to match and delete blog entries from a txt file before creating a sitemap.xml
# Contents of filename:
# http://www.example.com/2008/10/article3.html
# http://www.example.com/2009/11/article7.html
#!/bin/bash
hostName="www.example.com"
hostTLD="$(echo ${hostName}|cut -d . -f 3)" # results in "com"
sed -i '/\.'"${hostTLD}"'\/\([0-9]{4}\)\/\([0-9]{2}\)/d' filename
I can’t figure out how to match the year/month bits. I want to remove all lines that contain “.TLD/year/month/”
I know the $hostTLD part works because I’m using it with a different match:
sed -i '/\.'"${hostTLD}"'\/category\//d' filename # works! ".TLD/category/"
You were close, but you needed to use double-quotes around your
sedcommand and escape the braces. Try this instead:For your second command, use this: