in reply to mv files from dir1 to dir2

I'm pretty sure it's because your regex is wrong, which I mentioned in your other node Re^5: Processing data in on dir and copying, then processing into another dir . Give the exact filenames you are trying that regex with.
@files = grep /^(\d+\D\d)_(LacZ|pgK|SD|SU)(.*)$/,@files; # is not doing what you think

I'm not really a human, but I play one on earth Remember How Lucky You Are

Replies are listed 'Best First'.
Re^2: mv files from dir1 to dir2
by lomSpace (Scribe) on Jan 12, 2009 at 17:49 UTC
    Here are file name examples:
    12774L1_LacZ.SEE.rc_C06_2008-12-01.ab1
    12774L1_pgK.Neo.2fw_D06_2008-12-01.ab1,
    12774L1_SD_B06_2008-12-01.ab1
    12774L1_SU_A06_2008-12-01.ab1
    My regex,/^(\d+\D\d)_(LacZ|pgK|SD|SU)(.*)$/, should capture any of these?
      Yes. But you could have answered that question yourself with a short experiment:
      use strict; use warnings; while (<DATA>) { if (/^(\d+\D\d)_(LacZ|pgK|SD|SU)(.*)$/) { print "match: $_"; print ' $1', " is $1\n"; print ' $2', " is $2\n"; print ' $3', " is $3\n"; } else { print "no match: $_"; } } __DATA__ 12774L1_LacZ.SEE.rc_C06_2008-12-01.ab1 12774L1_pgK.Neo.2fw_D06_2008-12-01.ab1 12774L1_SD_B06_2008-12-01.ab1 12774L1_SU_A06_2008-12-01.ab1 foo.bar

      prints:

      match: 12774L1_LacZ.SEE.rc_C06_2008-12-01.ab1 $1 is 12774L1 $2 is LacZ $3 is .SEE.rc_C06_2008-12-01.ab1 match: 12774L1_pgK.Neo.2fw_D06_2008-12-01.ab1 $1 is 12774L1 $2 is pgK $3 is .Neo.2fw_D06_2008-12-01.ab1 match: 12774L1_SD_B06_2008-12-01.ab1 $1 is 12774L1 $2 is SD $3 is _B06_2008-12-01.ab1 match: 12774L1_SU_A06_2008-12-01.ab1 $1 is 12774L1 $2 is SU $3 is _A06_2008-12-01.ab1 no match: foo.bar

      Update: Furthermore, grep properly filters out the "foo.bar" file I injected:

        True
      It looks to me, like your $topdir, in your script, has Results_2008 on the hardcoded path, where my script, finds Results_2008 as a subdir, as your original specification was. So you have a path_logic error.

      I'm not really a human, but I play one on earth Remember How Lucky You Are
        Yes, under "/home/lomspace/testdir1/RESULTS 2008" there is
        /home/lomspace/testdir1/RESULTS 2008/DEC 2008/Results 12-01-08C
        The subdirs under /RESULTS 2008 all have the month and year.
        I want to peek into the dirs that start with /Results /d/d-/d/d-/d/d/D.
        If the have files that I want then I will move them, if not next peek into the next dir.
      Your script with those filenames works here:

      in /testdir1/Results_2008:

      12774L1_LacZ.SEE.rc_C06_2008-12-01.ab1 12774L1_SD_B06_2008-12-01.ab1 12774L1_pgK.Neo.2fw_D06_2008-12-01.ab1 12774L1_SU_A06_2008-12-01.ab1

      in /testdir1/Results_2009: no files

      My script:

      #!/usr/bin/perl use warnings; use strict; my $topdir = "/home/zentara/testdir1"; my @subdirs = get_sub_dirs($topdir); my $newdir = "/home/zentara/testdir2"; sub get_sub_dirs { my $dir = shift; opendir my $dh, $dir or die "Error: $!"; # print "$dh\n"; #this is your glob my @dirs = readdir $dh; @dirs = grep /^Results(.*)$/,@dirs; closedir $dh; return @dirs; } print "subdirs = @subdirs\n"; foreach my $dir(@subdirs){ opendir my $dh, "$topdir/$dir" or die "Error: $!"; my @files = readdir $dh; print "raw files = @files\n"; @files = grep /^(\d+\D\d)_(LacZ|pgK|SD|SU)(.*)$/,@files; print "$dir -> @files\n"; foreach my $file(@files){ # system( "mv $topdir/$dir/$file $newdir/$file"); } closedir $dh; }
      OUTPUT:

      subdirs = Results_2008 Results_2009

      raw files = . .. 12774L1_SU_A06_2008-12-01.ab1 12774L1_pgK.Neo.2fw_D06_2008-12-01.ab1 12774L1_LacZ.SEE.rc_C06_2008-12-01.ab1 12774L1_SD_B06_2008-12-01.ab1

      Results_2008 -> 12774L1_SU_A06_2008-12-01.ab1 12774L1_pgK.Neo.2fw_D06_2008-12-01.ab1 12774L1_LacZ.SEE.rc_C06_2008-12-01.ab1 12774L1_SD_B06_2008-12-01.ab1

      raw files = . .. Results_2009 ->

      You must have some overlooked spelling error in your pathnames or something?


      I'm not really a human, but I play one on earth Remember How Lucky You Are
        Thanks for the help with getting the "glob".
        Duh! on my part. Now that I can see the dirs that I want to
        search. I need to look into the subdir to see if I want to move it to testdir2.
        So the first file in each dir that I want to mv to testdir2 will be similar
        to:
        12635L1_LacZ.SEE.rc_G03_2008-12-01.ab1
        12635L1_pgK.Neo.2fw_H03_2008-12-01.ab1
        12635L1_SD_F03_2008-12-01.ab1
        12635L1_SU_E03_2008-12-01.ab1 The dir could start with anyone of them based on the regex. This is a unique file naming convention.
        Now that I have the $topdir should I do another foreach to read through the dirs?
        I need to peek into these subdirs to determine is I will mv to testdir2:
        Results 12-01-08A Results 12-05-08C Results 12-15-08C Results 12-18 +-08D Results 12-01-08B Results 12-08-08A Results 12-15-08D Results 12-19 +-08A Results 12-01-08C Results 12-08-08B Results 12-15-08E Results 12-19 +-08B Results 12-01-08D Results 12-08-08C Results 12-15-08F Results 12-19 +-08C Results 12-02-08A Results 12-09-08A Results 12-15-08G Results 12-19 +-08D Results 12-02-08B Results 12-09-08B Results 12-15-08H Results 12-22 +-08A Results 12-02-08C Results 12-10-08A Results 12-16-08A Results 12-22 +-08B Results 12-03-08A Results 12-10-08B Results 12-16-08B Results 12-23 +-08A Results 12-03-08B Results 12-10-08C Results 12-17-08A Results 12-23 +-08B Results 12-04-08A Results 12-11-08A Results 12-17-08B Results 12-23 +-08C Results 12-04-08B Results 12-11-08B Results 12-18-08A Results 12-05-08A Results 12-15-08A Results 12-18-08B Results 12-05-08B Results 12-15-08B Results 12-18-08C