homepage Welcome to WebmasterWorld Guest from 54.205.144.54
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
Forum Library, Charter, Moderators: bakedjake

Linux, Unix, and *nix like Operating Systems Forum

    
Can touch do this ?
touch bash
jehoshua




msg:4646915
 4:13 am on Feb 20, 2014 (gmt 0)

I have hundreds of files that are being converted, and after they have been converted, I need to use touch to modify the timestamp on each new file. Is there is bash script that looks for all files with a .wps file extension, and can touch the new filename that has a .doc file extension ?

Example .., a ls command of all the .wps files

Apr 7 1998 Fred.wps
Apr 7 1998 Resume1.wps
Feb 4 1999 rody.wps
Nov 16 1998 Rudi.wps
May 21 1998 save1.wps
Dec 2 1997 testprnt.wps

and then an ls command of all the .doc files

Oct 21 21:32 Resume1.doc
Oct 21 21:33 RESUME.doc
Oct 21 21:34 rody.doc
Oct 21 21:35 Rudi.doc
Oct 21 21:36 save1.doc
Oct 21 21:36 testprnt.doc

so the first file (Fred.wps) won't find a match, the second file has a timestamp of Apr 7 1998 3:51:04 PM. So the bash script would replace the timestamp on Resume1.doc to Apr 7 1998 3:51:04 PM

 

incrediBILL




msg:4646921
 4:48 am on Feb 20, 2014 (gmt 0)

This might work if I understand your needs correctly

find . -name "*.wps" -print | cut -d'.' -f2 | xargs -I % echo %.doc

First we FIND each .wps file, cut the ".wps" off and show just the file name, then we take all those file names using xargs and feed them into echo one at a time and append ".doc"

If that works for you, replace echo with touch and shown below and let 'er rip!

find . -name "*.wps" -print | cut -d'.' -f2 | xargs -I % touch %.doc

Hope that solves your problem, or gets you close enough to working it out

jehoshua




msg:4646923
 5:15 am on Feb 20, 2014 (gmt 0)

Thanks incrediBILL, the first part worked, and when I tried the second part I got this

touch: cannot touch `/Resume1.doc': Permission denied


The file is 644. I'm the owner and group ? I can touch a file individually in a GUI though. ?

The find with the echo returned this ..


/Fred.doc
/Resume1.doc
/rody.doc
/Rudi.doc
/save1.doc
/testprnt.doc


Should the forward slash be there ?

incrediBILL




msg:4646926
 5:32 am on Feb 20, 2014 (gmt 0)

note the file path /Resume1.doc, the file is at the root?

jehoshua




msg:4646927
 5:37 am on Feb 20, 2014 (gmt 0)

Yes, the file is at the root.

(I've done a cd into that path, to test it, so Resume1.doc won't have a forward slash.)

[edited by: jehoshua at 6:07 am (utc) on Feb 20, 2014]

incrediBILL




msg:4646937
 6:06 am on Feb 20, 2014 (gmt 0)

oops

Try this:
ind . -name "*.wps" -print | cut -d'.' -f2 | cut -d'/' -f2 | xargs -I % echo %.doc

jehoshua




msg:4646944
 6:20 am on Feb 20, 2014 (gmt 0)

Thanks, that did the echo okay. The touch worked to a degree. It touched them with todays date/time. If I have a file Apr 7 1998 09:23;50 AM Resume1.wps , it has been converted to Oct 21 2013 21:32:00 Resume1.doc

I need to touch Resume1.doc with Apr 7 1998 09:23;50

jehoshua




msg:4646955
 7:24 am on Feb 20, 2014 (gmt 0)

This worked for the touch ..

find . -name "*.wps" -print | cut -d'.' -f2 | cut -d'/' -f2 | xargs -I % touch %.doc -r %.wps


Thanks VERY much for all your help. :D

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved