[NTLUG:Discuss] Script question: give me the next sequential filename....
Fred James
fredjame at concentric.net
Mon Mar 31 10:46:38 CST 2003
Jack Snodgrass wrote:
>I need to create a log. It needs to be called
>makefile.yymmdd-x where
>makefile.yymmdd can be done with something like
>makefile.`date +DATE: '%y%m%d`
>
>...now the catch... the first time I run this today, I want
>makefile.030331-1
>the next time I want
>makefile.030331-2
>and then
>makefile.030331-3
>etc.
>
>Is there a simple way to do this from bash or csh.
>
>I know that I can use php or rexx or perl to do this,
>but can I do it from simple scripting commands?
>
>Thanks - jack
>
>
How about something like
>>
N=`ls -1 | grep makefile | grep `date '+%y%m%d'` | awk -F"-"
'BEGIN{Cnt=0}{if($NF > Cnt){Cnt = $NF}}END{print Cnt}'`
N=`expr $N + 1`
FileName="makefile.`date '+%y%m%d'`-$N"
<<
it works in GNU bash, version 2.05a.0(1)-release (i686-pc-linux-gnu) anyway.
--
"It's not nice to fool Mother OS." --anonymous
More information about the Discuss
mailing list