Sed match date in wordpress url

Using sed I had a problem trying to match and delete blog entries from a txt file before creating a sitemap.xml file

# 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 cannot figure out how to match the year / month bits. I want to delete all rows containing ".TLD / year / month /"

I know that part of $ hostTLD works because I use it with a different match:

 sed -i '/\.'"${hostTLD}"'\/category\//d' filename # works! ".TLD/category/" 
+4
source share
1 answer

You were around, but you had to use double quotes around your sed command and avoid the parentheses. Try instead:

 sed -i "/\.$hostTLD\/[0-9]\{4\}\/[0-9]\{2\}/d" filename 

For your second command, use this:

 sed -i "/\.$hostTLD\/category\//d" filename 
+1
source

All Articles