for dateNfile in $(grep dateishere *html | sed -r 's/^([^:]*):(.*)dateishere/\2:\1/' | sort -n) do echo name=${dateNfile/*:/} # echo date=${dateNfile/:*/} mv $name /other/location done So I guess there is just one line per file, containing 'dateishere', and that the line starts with the date, but the sed command could be modified, to cut the date even in other cases.
If you have blanks in the filenames, or linebreaks and such, things get a bit more complicated, so I would like to ignore these, if possible. But from your assertion, this isn't the case.