[Charlug] command line help please

Mark a.booker4 at ntlworld.com
Wed Dec 23 06:00:53 EST 2009


Thanks Ryan, that was exactly what I was after, the explanation helped a 
lot too!

-------- Original Message --------
Subject: Re: [Charlug] command line help please
From: Ryan Sawhill <ryan at open-pros.com>
To: Mark <a.booker4 at ntlworld.com>
Date: Wed Dec 23 2009 11:06:01 GMT-0500 (Eastern Standard Time)

> ----- Original Message -----
> From: "Mark" <a.booker4 at ntlworld.com>
> Cc: charlug at charlug.org
> Sent: Tuesday, December 22, 2009 10:53:47 PM
> Subject: Re: [Charlug] command line help please
> 
> Thanks Clark, I tried it out in bash, but receive this error message:
> 
> touch: invalid date format `filename_*.ext'
> ---------------------------
> 
> 
> Here you go Mark.
> 
> for i in * ; do touch -t `echo $i | sed -e s at .*_@@ -e 's at .jpg$@@'` $i; done
> 
> Additional info which may or may not be obvious...
> * You can use any list of files or whatever kind of glob you want instead of a single asterisk.
> * Semicolons can be replaced with hard returns.
> * Full explanation: With this loop, for every file ($i), we are running one touch command to change its timestamp. To grab the ts, we need to use backticks to get some command substitution going. In there, were using sed (a search&replace editor) to 1) strip out everything before the first underscore and 2) to remove ".jpg" from the end. Sed's usual syntax (for what we're doing here anyway) is
> sed s/SEARCH STRING/REPLACE STRING/ [filename]
> The character immediately after "s" is the delimiting character and is arbitrary.
> Quoting the whole search/replace expression is a good habit to get into, but not always necessary.
> 
> Enjoy!
> 


More information about the CharLUG mailing list