Moving files listed in a data file to a new directory using Perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Moving files listed in a data file to a new directory using Perl
# 1  
Old 01-14-2010
Moving files listed in a data file to a new directory using Perl

Hi,
I have a data file that lists a number of files. I want to move the files named in that one to another directory. Here's what I have:
Code:
#!/usr/bin/perl -w
open(FILE, "<collision.txt");
my @lines=<FILE>;
foreach my $lines (@lines) {
    system("mv $lines collisions/.");
}
close(FILE);

When I use this is tells me "mv: missing destination file operand after (the file name)" Can anyone tell me what I'm doing wrong?
Thanks!

Last edited by pludi; 01-15-2010 at 02:20 AM.. Reason: code tags, please...
# 2  
Old 01-14-2010
use chomp

Code:
foreach my $lines (@lines) {
chomp $lines;
system("mv $lines collisions/.");
}

The whole code can be simplified to

Code:
open FILE , '<' , "collision.txt" || die "$!";
while (<FILE>){
        chomp;
        system("mv $_ collisions/");
}
close FILE;

# 3  
Old 01-15-2010
Thanks! It worked perfectly!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

In PErl script: need to read the data one file and generate multiple files based on the data

We have the data looks like below in a log file. I want to generat files based on the string between two hash(#) symbol like below Source: #ext1#test1.tale2 drop #ext1#test11.tale21 drop #ext1#test123.tale21 drop #ext2#test1.tale21 drop #ext2#test12.tale21 drop #ext3#test11.tale21 drop... (5 Replies)
Discussion started by: Sanjeev G
5 Replies

2. Shell Programming and Scripting

Want to delete the junk files from a directory which are not listed in a TEXT file

Hello Everyone, I want to delete the image files from a directory, which are not listed in a TEXT file. The directory contains large number of image files (in millions) required / not required. I want to delete the image files which are "not required". I have generated a Text file having... (3 Replies)
Discussion started by: Praveen Pandit
3 Replies

3. Shell Programming and Scripting

Cat files listed in text file and redirect to new directory with same filename

I have a directory that is restricted and I cannot just copy the files need, but I can cat them and redirect them to a new directory. The files all have the date listed in them. If I perform a long listing and grep for the date (150620) I can redirect that output to a text file. Now I need to... (5 Replies)
Discussion started by: trigger467
5 Replies

4. Shell Programming and Scripting

perl Compare zone files in directory with what is listed in named.conf

I would really appreciate any assistance that I can get here. I am fairly new to perl. I am trying to rewrite my shell scripts to perl. Currently I have a shell script (using sed, awk, grep, etc) that gets a list of all of the zone files in a directory and then looks in named.conf for what... (0 Replies)
Discussion started by: brianjb
0 Replies

5. Shell Programming and Scripting

Copy files listed in text file to new directory

I am trying to write a script that will copy all file listed in a text file (100s of file names) to a new directory Assume script will run with main as current working directory and I know how many files/lines will be in List.txt Im trying to work up a test script using this model Contents of... (2 Replies)
Discussion started by: IAmTheGrass
2 Replies

6. UNIX for Dummies Questions & Answers

Reading the dates from a file & moving the files from a directory

Hi All, I am coding for a requirement where I need to read a file & get the values of SUB_DATE. Once the dates are found, i need to move the files based on these dates from one directory to another. ie, this is how it will be in the file, SUB_DATE = 20120608,20120607,20120606,20120606... (5 Replies)
Discussion started by: dsfreddie
5 Replies

7. Shell Programming and Scripting

Grepping file names, comparing them to a directory of files, and moving them into a new directory

got it figured out :) (1 Reply)
Discussion started by: sHockz
1 Replies

8. Shell Programming and Scripting

Cut the first column in listed files > PERL script

Hi All, Using this command wc -l *e* > create2.txt i'm getting the following output >>>create2.txt listed output files, my requirement is how to cut the first coloum in all the files mentioned in create2.txt in perl. 50 allignment.pl 3 create.txt 4 application.txt ... (8 Replies)
Discussion started by: adaleru
8 Replies

9. Shell Programming and Scripting

Creating date directory and moving files into that directory

I have list of files named file_username_051208_025233.log. Here 051208 is the date and 025233 is the time.I have to run thousands of files daily.I want to put all the files depending on the date of running into a date directory.Suppose if we run files today they should put into 05:Dec:08... (3 Replies)
Discussion started by: ravi030
3 Replies

10. HP-UX

CVSWeb - Directories listed but files not listed

I am using CVSWeb on HPUnix. When i access it, all directories are listed but files are not listed. I am getting the error "NOTE: There are 51 files, but none matches the current tag. " in tomcat sevrer log i am getting the message "rlog warning: Missing revision or branch number after -r"... (0 Replies)
Discussion started by: ganesh
0 Replies
Login or Register to Ask a Question