[Charlug] command line help please

Mark a.booker4 at ntlworld.com
Tue Dec 22 22:53:47 EST 2009


Thanks Clark, I tried it out in bash, but receive this error message:

touch: invalid date format `filename_*.ext'

any ideas?
-Mark

-------- Original Message --------
Subject: Re: [Charlug] command line help please
From: Clark Hale <xlark at sdf.lonestar.org>
To: Mark <a.booker4 at ntlworld.com>
Date: Tue Dec 22 2009 04:07:05 GMT-0500 (Eastern Standard Time)

> On Tue, Dec 22, 2009 at 1:17 AM, Mark <a.booker4 at ntlworld.com> wrote:
>> Hi there, I'm trying to think of an easy way to do this, basically I have a
>> bunch of files with this naming format:
>>
>> filename_YYYYMMDDhhmm.ext
>>
>> I want to extract the YYYYMMDDhhmm part of each filename to use with 'touch'
>> to change the datestamp:
>> eg:
>> touch filename_200912220115.jpg -t 200912220115
>>
>> Can someone suggest a way to automate this? I would like to be able to
>> process a whole directory at once, preferably a one-line command using
>> pipes.
> 
> So long as you're using a Bourne-type shell (e.g. bash), probably
> something like this would do the trick.
> 
> for i in filename_*.ext
> do
> touch $i -t `echo $i | sed -e 's/filename_\([0-9]\).ext/\1/'`
> done
> 
> Depeding on how many files there are, your shell might barf.  I know
> on AIX, there's an upper limit that's obscenely low (512 character
> maximum for the filename_*.ext glob.  I think), but I'm not sure about
> Linux these days.
> 
> Basic caveat emptor:  YMMV, test first, &c.
> 
> HTH,
> 
> -CFH
> 


More information about the CharLUG mailing list