Touch Challenge

I’ve been given a directory full of subdirectories full of logfiles of the same name:

/logfiles/day1/file1/blockednodes.csv
day1-14
file1-48

The above is the actual directory structure for 14 days worth of a logfile that is generated every 30 minutes. It’s been done this way to preserve the identicle file name “blockednodes.csv”

I’ve been tasked with using touch to update each of the 48 files, for each of the 14 days, with the date and time from 0000 on 25/07/2012 onwards.

I have managed the following line so far, but can’t seem to get figure out how to include the time?

for i in {1…14}; do for j in {1…48}; do echo $(date +%Y%m%d --date=“2012-07-24 + $i days”) Day$i/File$j/BlockedNodes.csv; done; done

Output:
20120725 Day1/File1/BlockedNodes.csv
20120725 Day1/File2/BlockedNodes.csv
20120725 Day1/File3/BlockedNodes.csv
20120726 Day2/File1/BlockedNodes.csv
20120726 Day2/File2/BlockedNodes.csv
20120726 Day2/File3/BlockedNodes.csv

Can anyone suggest a way of adding the hour and minute in here?

Any help is appreciated.

Thanks and regards
Cludgie

First, let me say “I’m no programmer” … and I’m also not 100% sure what you’re asking … but does this help ?

Here’s a couple of examples that create a file with the date and time in their name … as in:-

BlockedNode_2012-08-05_15:38.csv
and
BlockedNode_2012-08-05_15:38:37.csv

touch BlockedNode_`date +%Y`-`date +%m`-`date +%d`_`date +%H`:`date +%M`.csv

or if you want seconds too:

touch BlockedNode_`date +%Y`-`date +%m`-`date +%d`_`date +%H`:`date +%M`:`date +%S`.csv

Here’s a list of field descriptors:-

%a Displays the locale’s abbreviated weekday name.
%A Displays the locale’s full weekday name.
%b Displays the locale’s abbreviated month name.
%B Displays the locale’s full month name.
%c Displays the locale’s appropriate date and time representation. This is the default.
%C Displays the century as a decimal number (00-99). A year is divided by 100 and truncated to an integer.
%d Displays the day of the month as a decimal number (01-31). In a two-digit field, a 0 is used as leading space fill.
%D Displays the date in the format equivalent to %m/%d/%y.
%e Displays the day of the month as a decimal number (1-31). In a two-digit field, a blank space is used as leading space fill.
%h Displays the locale’s abbreviated month name (a synonym for %b).
%H Displays the hour (24-hour clock) as a decimal number (00-23).
%I Displays the hour (12-hour clock) as a decimal number (01-12).
%j Displays the day of year as a decimal number (001-366).
%m Displays the month of year as a decimal number (01-12).
%M Displays the minutes as a decimal number (00-59).
%n Inserts a character.
%p Displays the locale’s equivalent of either AM or PM.
%r Displays 12-hour clock time (01-12) using the AM-PM notation; in the POSIX locale, this is equivalent to %I:%M:%S %p.
%S Displays the seconds as a decimal number (00- 59).
%t Inserts a character.
%T Displays the 24-hour clock (00-23) in the format equivalent to HH:MMS .
%u Displays the weekday as a decimal number from 1-7 (Sunday = 7). Refer to the %w field descriptor.
%U Displays week of the year(Sunday as the first day of the week) as a decimal number[00 - 53] . All days in a new year preceding the first Sunday are considered to be in week 0.
%V Displays the week of the year as a decimal number from 01-53 (Monday is used as the first day of the week). If the week containing January 1 has four or more days in the new year, then it is considered week 01; otherwise, it is week 53 of the previous year.
%w Displays the weekday as a decimal number from 0-6 (Sunday = 0). Refer to the %u field descriptor.
%W Displays the week number of the year as a decimal number (00-53) counting Monday as the first day of the week.
%x Displays the locale’s appropriate date representation.
%X Displays the locale’s appropriate time representation.
%y Displays the last two numbers of the year (00-99).
%Y Displays the year with century as a decimal number.
%Z Displays the time-zone name, or no characters if no time zone is determinable.
%% Displays a % (percent sign) character.

As for adding that automagically to already existing filenames in subdirs with 30 minute spacing … I’ll have to leave that to you (or anyone else that responds) … but maybe that will point you in the right direction ?