Welcome to WebmasterWorld Guest from 54.167.155.147

Forum Moderators: bakedjake

Message Too Old, No Replies

Can touch do this ?

touch bash

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

10+ Year Member



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
4:48 am on Feb 20, 2014 (gmt 0)

WebmasterWorld Administrator incredibill is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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
5:15 am on Feb 20, 2014 (gmt 0)

10+ Year Member



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 ?
5:32 am on Feb 20, 2014 (gmt 0)

WebmasterWorld Administrator incredibill is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



note the file path /Resume1.doc, the file is at the root?
5:37 am on Feb 20, 2014 (gmt 0)

10+ Year Member



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]

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

WebmasterWorld Administrator incredibill is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



oops

Try this:
ind . -name "*.wps" -print | cut -d'.' -f2 | cut -d'/' -f2 | xargs -I % echo %.doc
6:20 am on Feb 20, 2014 (gmt 0)

10+ Year Member



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
7:24 am on Feb 20, 2014 (gmt 0)

10+ Year Member



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