[Charlug] command line help please
Ryan Sawhill
ryan at open-pros.com
Wed Dec 23 11:06:01 EST 2009
----- 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!
--
Ryan Sawhill, RHCE, RHCX
Open Professionals, LLC
gpg: D5914682 E5D2 815E C4DF 60EF 7417 0D84 DF98 7C98 D591 4682
More information about the CharLUG
mailing list