[NTLUG:Discuss] Script question

MadHat madhat at unspecific.com
Fri Jan 4 12:00:43 CST 2002


try something like this using awk

for x do
   n=`echo $x | awk -F . '{ $3++ };  { print $1"."$2"."$3 }'`
   echo "mv -f $x $n"
done


I made this a shell script called 'rename' and run
$ rename /var/log/filename*
the echo is just to show what is going on, once verified, it is just 'mv -f 
...'.  If you are already in a loop in a script, just use the awk part.  I 
am sure there are more elegant ways of doing this, but this works.


At 08:18 AM 1/4/2002 -0600, you wrote:
>Would someone please help me over another "hump"? I'm still learning...
>
>I maintain the current version and 3 previous versions of the file
>"domains". The files are all in the same directory and the file name
>includes a unique date/time stamp and a version number. For example:
>
>domains.2002-01-04_050500.0
>domains.2002-01-02_052515.1
>domains.2002-01-01_043025.2
>domains.2001-12-30_050500.3
>
>'0' is the current version and '3' is the oldest.
>
>When a new file is created I want to "age" the files and create an open
>slot for a new "0" file (3 goes away, 2 becomes 3, 1 becomes 2, and 0
>becomes 1). I don't know the date/time stamps, so this is what I tried
>in my script:
>
>mv -f /archive/domains.*.2 /archive/domains.*.3
>mv -f /archive/domains.*.1 /archive/domains.*.2
>mv -f /archive/domains.*.0 /archive/domains.*.1
>
>The asterisk apparently acts as a wildcard during the file selection
>part of the command, but it is acting as a literal in the renaming
>porting of the command (I end up with files named domains.*.3).
>
>How can I rewrite this to accomplish the task?
>
>Thanks in advance!
>
>Rick Matthews
>
>
>_______________________________________________
>http://www.ntlug.org/mailman/listinfo/discuss

--
MadHat at unspecific.com





More information about the Discuss mailing list