Copy an array to a newly created directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copy an array to a newly created directory
# 1  
Old 04-02-2013
Copy an array to a newly created directory

hello everyone,

I am new to perl script and trying to develop a script as follows.

I am trying to Create an array for storing all file names. I am trying to copy $libs[1] into "scratch". however i am unable to do so. Please suggest..



Code:
#!/usr/bin/perl

use File::Copy;

#use Archive::Zip qw( :ERROR_CODES );

$my_file = "makefile";
open(HANDLE,"<$my_file");

#$output_file = "libs.txt";
#open (OUTPUT, ">$output_file");


while(<HANDLE>)
{
	if(/check_geomtools.exe:/./\.lib$/)
	{
	 @libs = split(/: /);
	 @nlibs = $libs[1];
	 mkdir "Scratch";
	 foreach $my_libs(@nlibs)
	 {
		copy($my_libs, Scratch)
	 }

	}
	 	
}


close HANDLE;


Last edited by Rashid Khan; 04-02-2013 at 04:31 AM..
# 2  
Old 04-02-2013
What that if statement achieves is a check on the successful concatenation of the results of performing 2 separate regex checks /check_geomtools.exe:/ and /\.lib$/.

I take it you actually want to match a line of the form:
Code:
/check_geomtools.exe:/.*\.lib$/

Your split probably wants to be on just a colon, rather than a colon followed by a space.

Your bizarre assumption that the split statement would result in a multi-dimensional array is incorrect...

So taking these on board...
Code:
#!/usr/bin/perl

use strict;     #These two lines will
use warnings; # save you hours of debugging time
use File::Copy;

my $my_file = "makefile";
open(my $makefile,'<', "$my_file");


while(<$makefile>)
{
	if(/check_geomtools.exe:.*./\.lib$/)
	{
        chomp;
	my (@libs = split(/:/,$_));
	 mkdir "Scratch";
	 foreach my $my_libs(@libs)
	 {
		copy($my_libs, Scratch)
	 }

	}
	 	
}

# 3  
Old 04-02-2013
Thanks for the reply, however the code is unable to serve the purpose.

let me breif you.

I have a file which contains the following:

Code:
E:\gtmproj\script\i486_nt\obj\check_geomtools.exe: o:\portsrc\spg\system_1\i486_nt\advapps\TK-2\objmt\winclockmtq.lib
E:\gtmproj\script\i486_nt\obj\check_geomtools.exe: o:\portsrc\spg\system_1\i486_nt\advapps\TK-2\objmt\unifilesmtq.lib
E:\gtmproj\script\i486_nt\obj\check_geomtools.exe: o:\portsrc\spg\system_1\i486_nt\advapps\TK-2\objmt\dlmmgrmtq.lib
E:\gtmproj\script\i486_nt\obj\check_geomtools.exe: o:\portsrc\spg\system_1\i486_nt\advapps\TK-2\objmt\asyncoremtq.lib
E:\gtmproj\script\i486_nt\obj\check_geomtools.exe: o:\portsrc\spg\system_1\i486_nt\advapps\TK-2\objmt\baselibmtq.lib
E:\gtmproj\script\i486_nt\obj\check_geomtools.exe: o:\portsrc\spg\system_1\i486_nt\advapps\TK-2\objmt\i18nmtq.lib
E:\gtmproj\script\i486_nt\obj\check_geomtools.exe: o:\portsrc\spg\system_1\i486_nt\advapps\TK-2\objmt\utfstrmtq.lib
E:\gtmproj\script\i486_nt\obj\check_geomtools.exe: o:\portsrc\spg\system_1\i486_nt\advapps\TK-2\objmt\rtlcoremtq.lib
E:\gtmproj\script\i486_nt\obj\check_geomtools.exe: o:\portsrc\spg\system_1\i486_nt\advapps\TK-2\objmt\btkzlibmtq.lib

After splitting the path i am trying to copy "$libs[1]" to the directory named "scratch". once "$libs[1]" i copied to scratch. I need to zip(scratch) and copy it to some other location and lastly, delete scratch.

I hope the issue is clear now.Smilie

Last edited by jim mcnamara; 04-02-2013 at 09:21 AM..
# 4  
Old 04-02-2013
Please do not multi post your issues.!!
# 5  
Old 04-02-2013
hi pikk45.

sorry for the multipost. I am facing problems in copying the files. Could you please assist me in that.

thanks.
# 6  
Old 04-02-2013
try the following:
Code:
#!/usr/bin/perl

use strict;     #These two lines will
use warnings; # save you hours of debugging time
use File::Copy;
use File::Basename;

my $my_file = "makefile";
open(my $makefile,'<', "$my_file");


while(<$makefile>)
{
	if(/check_geomtools.exe: (.*./\.lib)$/){
          my $full_path=$1;
          chomp($full_path);
          my $filename = basename($full_path);
          mkdir "Scratch" if ( ! -d Scratch) ;
	  copy($full_path, "Scratch/$filename");
	}
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

No iscsi available in newly created AIX wpar

AIX 7.1 New to WPAR, hopefully just missing something simple here. Creating the WPAR like this..... (The box where the WPAR is hosted does have an iscsi protocol device) mkwpar -h wpar08 -l -n wpar08 -N interface=en0 address=xxx.xx.xx.xxx netmask=255.255.255.0 -D devname=/dev/iscsi0 -D... (0 Replies)
Discussion started by: TomR
0 Replies

2. Hardware

Formatting a newly created lun

Hi , I have created one new lun in my SAN storage and make it visible to my HP servers , but the fdisk -l output is somehow confusing. Do not know what to do next ---------- fdisk -l /dev/sdo1 Disk /dev/sdo1 (Sun disk label): 64 heads, 32 sectors, 10238 cylinders Units =... (7 Replies)
Discussion started by: mishra.sankar
7 Replies

3. Solaris

Can't see Newly created LUN by SAN admin

hello, i am an oracle DBA and trying to scan a newly created LUN of 200 GB on fiber channel by SAN admin.we have solaris 10 and SANtoolkit is installed.i tried following to get the new LUN at my machine. go /opt/Netapp/Santoolkit/bin and then ./sanlun lun show but i see only the existing... (12 Replies)
Discussion started by: janakors
12 Replies

4. UNIX for Advanced & Expert Users

default size of a newly created folder

Hi all, In linux how to create a directory with specified size, so that it can be used only up to the mentioned size. Actually my question is, whether we can do directory quota in linux. mounting the directory in a partiton will do that, but do we have any other option... (1 Reply)
Discussion started by: anishkumarv
1 Replies

5. Shell Programming and Scripting

sftp - get newly created files on incremental basis

Hi, We have a sftp server which creates files daily and keeps 6 months of files on the server. We are creating a daily job to get the files and load into database. My problem is "how to get ONLY those files which got created after my last get". Let me provide some more details to it. Below... (15 Replies)
Discussion started by: ravi.videla
15 Replies

6. Shell Programming and Scripting

How to find the newly created directory

Hi, I need to create new directory by increasing the number by 1 of extracted lastly created directory. e.g. Log\out_log_1\ Log\out_log_2\ Log\out_log_3\ become Log\out_log_1\ Log\out_log_2\ Log\out_log_3\ Log\out_log_4\ Can anyone help how to do it in c-shell... (3 Replies)
Discussion started by: Andre_2008
3 Replies

7. Shell Programming and Scripting

To copy a a file to last created directory..Urgent pls

I need to copy a file example hhh.txt to the recently created directory by name flexite@latesttimestamp in the path interface/home/ ... I couldnt get the name of recently created directory .... first result of ls -lst ...that is ls -lst |head -2 gives the latest directory but i could not... (2 Replies)
Discussion started by: helloo
2 Replies

8. Shell Programming and Scripting

How to keep appending a newly created file based on some keywords

Hi Friends, I have to create a new log file everyday and append it with content based on some keywords found in another log file. Here is what I have tried so far... grep Error /parentfolder/someLogFile.log >> /parentfolder /Archive/"testlogfile_error_`date '+%d%m%y'`.txt" grep error... (6 Replies)
Discussion started by: supreet
6 Replies

9. UNIX for Dummies Questions & Answers

Newly created files default group and write permissions

Whenever I create a new file the group name is "dnn" and the file permissions are "-rw-r--r--". How do I get it so when I create files (with vi or other programs) that the default group is "sss" and the permissions are 770? (I am running HP-UNIX) Thanks, GoldFish (2 Replies)
Discussion started by: goldfish
2 Replies

10. UNIX for Advanced & Expert Users

How to FTP all newly created but the current open file?

An application running on HP-UX constantly generates new text log files ( I think using logpipe ). Any new file created requires to be ftp'ed to an offline server, however I want to make sure that the current file being written should not be transferred. For examples consider the following files... (3 Replies)
Discussion started by: indianya
3 Replies
Login or Register to Ask a Question