this is a question similar to this one.
But I am not good at shell scripting, so I still want to ask you for help…
My situation is a little different: the date string is in the file.
These files (more than 700) are named msg00000.html to msg00721.html. Each one have a line like this:
<li><em>Date</em>: Thu, 22 Jul 2010 00:44:57 +0800</li>
After a lot of googling, I finally find them out using this:
grep "<li><em>Date" msg00000.html | cut -d' ' -f2-7 | tr -d "</li>"
The output is exactly what I want:
Thu, 22 Ju 2010 00:44:57 +0800
And I know use touch -md "Thu, 22 Ju 2010 00:44:57 +0800" msg00000.html can modify the mtime.
However, would anyone could help me combining them together? And do this for 723 files…
Thanks…
Edit
Well, I finally figured out how to:
for f in *.html; do touch -md "$(grep '<li><em>Date' $f | cut -d' ' -f2-7 | sed 's/<\/li>//')" "$f"; done
That’s quite a long command…
Actually the problem is in the tr command. It delete all the characters when using -d, not the pattern. So the date Thu, 22 Ju 2010 00:44:57 +0800 is wrong. It should be Thu, 22 Jul 2010 00:44:57 +0800. Yes, there is an “l” missing, which was deleted by tr -d. LOL.
I’m sure an awk guru will be along shortly to show us how to do it in 20 characters, but this should do the trick.
EDIT: Remember, kids, it’s important to get some sleep instead of trying to answer questions on the internet. You don’t want to end up posting ridiculous answers like this, do you?