Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to copy a file to a different location with a part of the file name as the filename

 
rahulJ james
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have set of files residing in my hone directory in different naming conventions as shown below,

ap_aearo_prod.20091104044210.Z.20091106.212217
ap_boise_prod.20091029064716_sorted.Z.20091106.212201
ap_boise_prod.20091029064716.Z.20091106.212158
arms_820i_prod.000003ywS.Z.20091109.064508

I wanted to copy these files to a different location with the filename being only till the "Z" i.e.; this file ap_aearo_prod.20091104044210.Z.20091106.212217 has to be copied as ap_aearo_prod.20091104044210.Z, have to truncate the part after the Z.

I have set of files under this directory. This set of files can be identified by the combination of ap_*_prod*20091106* as I need only these files from this datestamp, I have unwanted files with the same datestamp as well.

Can anyone advise
 
Himanshu Rawat
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried below code on your mentioned files. Give it a try.




PS : Script was in same directory where files are. Customise it
 
rahulJ james
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry I forgot to mention that I need the script in UNIX. I am sorry for that
 
Himanshu Rawat
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's perl script and ran it on linux/unix
 
rahulJ james
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when you say in your code as <*>, I beleive it will pick all the files under that directory but I want only the files matching as I have explained above
 
Himanshu Rawat
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


this to



This will take only those files starting with ap_

Hope this helps now

 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
create a local script

chmod a+x adhoc.sh, and

 
rahulJ james
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It worked. Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic