I have several folders with many html files and I need to batch search for specific information within these html and insert this information in the file name as a suffix

The information is: DATE | HOUR in the format below  

<p> 10 de junho de 2010 | 21h30 </p>

The information structure is the same in all html files, but the day, month, year and time are different in all files.

I am not able to indicate a regular expression for this and neither use grep and awk properly.

Any suggestions on how to extract this information and put it in the name file as a suffix?

  • You may wish to edit your question and clarify which OS you are running. Apr 16, 2020 at 18:15

1 Answer 1


In a bash environment (on Linux or CygWin under Windows), you can use:

$ LANG=es_ES-UTF-8 ; find . -type f -iname '*.html' | while IFS= read -r filename ; do ts=`stat --format=%Y "$filename"` ; suffix=`date --date=@$ts +%d\ de\ %B\ de\ %Y\ \|\ %Hh%M` ; mv "$filename" "$filename.$suffix" ; done

Assuming that:

  • you want to use Spanish language
  • you want to rename only files (not directories nor symlinks) with extension .html
  • you want to put as suffix date/time of data modification (not file creation, nor last access, nor last status change)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .