The magic AIX rename command

Clovertech Forums Read Only Archives Cloverleaf General The magic AIX rename command

  • Creator
    Topic
  • #49847
    Todd Lundstedt
    Participant

      I am looking for the magic command or script that allows me to rename many files at once… for instance, I have files named

      Code:

      stats/msgHist/2008/Feb/14/asp_test_fr_HCMC_adt_ib.2008Feb14_15:55:41_Thu.idx.Z
      stats/msgHist/2008/Feb/18/asp_test_fr_HCMC_adt_ib.2008Feb18_23:55:41_Mon.idx.Z
      stats/msgHist/2008/Feb/18/asp_test_fr_HCMC_adt_ib.2008Feb18_15:55:40_Mon.idx.Z
      stats/msgHist/2008/Feb/19/asp_test_fr_HCMC_adt_ib.2008Feb19_23:55:42_Tue.idx.Z
      stats/msgHist/2008/Feb/19/asp_test_fr_HCMC_adt_ib.2008Feb19_15:55:41_Tue.idx.Z
      stats/msgHist/2008/Feb/20/asp_test_fr_HCMC_adt_ib.2008Feb20_07:55:40_Wed.idx.Z
      stats/msgHist/2008/Feb/20/asp_test_fr_HCMC_adt_ib.2008Feb20_23:55:42_Wed.idx.Z
      stats/msgHist/2008/Feb/20/asp_test_fr_HCMC_adt_ib.2008Feb20_15:56:10_Wed.idx.Z
      stats/msgHist/2008/Feb/20/asp_test_fr_HCMC_adt_ib.2008Feb20_11:55:41_Wed.idx.Z
      stats/msgHist/2008/Feb/21/asp_test_fr_HCMC_adt_ib.2008Feb21_07:55:41_Thu.idx.Z
      stats/msgHist/2008/Feb/21/asp_test_fr_HCMC_adt_ib.2008Feb21_11:55:41_Thu.idx.Z

      and I want to chage the asp_test_ to asp_test.

      Code:

      stats/msgHist/2008/Feb/14/asp_test.fr_HCMC_adt_ib.2008Feb14_15:55:41_Thu.idx.Z
      stats/msgHist/2008/Feb/18/asp_test.fr_HCMC_adt_ib.2008Feb18_23:55:41_Mon.idx.Z
      .
      .
      .

      I am (almost) certain there is no way to do that in AIX.  I tried pulling it down to dos, and that got rid of the fr_HCMC_adt_ib string as well.

      Has anyone scripted this before?  If not, stay tuned, I am working on it.

    Viewing 2 reply threads
    • Author
      Replies
      • #63838
        Rob Abbott
        Keymaster

          You can use Tcl:

          Code:

          set file_list [glob *.Z]
          foreach file $file_list {
            set newfile [string map “asp_test_ asp_test.” $file]
            file rename $file $newfile
          }

          Rob Abbott
          Cloverleaf Emeritus

        • #63839
          Todd Lundstedt
          Participant

            GAH!

            I hate it when I get stuck on a problem and forget about other tools in my toolbox.  

            Thanks!

          • #63840

            I’ve been using this little script by Larry Wall for years.

            Code:

            #!/usr/bin/perl -w

            # renameFiles.pl
            #
            #  Discussion:
            #
            #    renameFiles.pl ‘tr/A-Z/a-z/’ *
            #
            #    will rename every file so that its name is lowercase.
            #
            #    renameFiles.pl ‘s/.orig$//’ *.orig
            #
            #    will, for every file that ends in “.orig”, rename the
            #    file by removing the trailing “.orig”.
            #
            #    renameFiles.pl ‘$_ .= “.old”‘ *.cc
            #
            #    will append “.old” to the name of every file that ends in “.cc”.
            #
            #  Modified:
            #
            #    20 March 2004
            #
            #  Author:
            #
            #    Larry Wall
            #
            #  Reference:
            #
            #    Tom Christiansen and Nathan Torkington,
            #    The Perl Coookbook,
            #    Chapter 9.9, Renaming Files
            #    O’Reilly, 1999

            $op = shift or die “Usage: renameFiles expr [files]n”;
            chomp(@ARGV = ) unless @ARGV;
            for ( @ARGV )
            {
             $was = $_;
             eval $op;
             die $@ if $@;
             rename ( $was, $_ ) unless $was eq $_;
            }

            -- Max Drown (Infor)

        Viewing 2 reply threads
        • The forum ‘General’ is closed to new topics and replies.