Sponsored Content
Full Discussion: Using Perl to Rename File
Top Forums Shell Programming and Scripting Using Perl to Rename File Post 302350645 by bbbngowc on Friday 4th of September 2009 11:53:31 AM
Old 09-04-2009
Quote:
Originally Posted by Vi-Curious
Code:
perl -e 'foreach (@ARGV) { rename($_, substr($_,7,14)) }' C*

Here's what I'm trying to do:

rename files like this:
ABCDEFG20090904024156.00565.txt
to this:
ABCDEFG.00565.txt

Like I said, I know nothing of perl. Will you code do this? Oh and the first 7 characters (ABCDEFG) are never the same.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Help with multiple file rename - change case of part of file name

Hi there, I hope someone can help me with this problem : I have a directory (/var/www/file/imgprofil) which contains about 10000 JPG files. They have a naming convention thus : prefix-date-key-suffix.jpg they all have the prefix p-20050608- then AAAA is a 4 letter code the suffix is... (7 Replies)
Discussion started by: steve7
7 Replies

2. Shell Programming and Scripting

rename does not work in perl

#!/usr/bin/perl -w use POSIX qw(strftime); $PID = strftime "%Y%m%d%H%M%S", localtime; $filename = "original.list"; rename($filename,$filename.$PID)|| print "rename failed\n"; print $filename;The above code has no syntax error. But the renaming does not work. Anybody got a clue? (1 Reply)
Discussion started by: new2ss
1 Replies

3. Shell Programming and Scripting

perl rename failed

i have a file, which i want to rename, from my current directory to a backupdirectory. My perl code is below rename($s_filename,$backup.$s_filename ) all my variables are defined. but the rename failed. the file permission my file is "-rw-rw-r--". could this be a problem? I tried to use the... (9 Replies)
Discussion started by: new2ss
9 Replies

4. UNIX for Dummies Questions & Answers

Rename file based on first 3 characters of data in file

I'm looking to determine if I can use a grep command to read file and rename the file based on the first 3 characters of the data in the file. An example is: Read FileA If the first 3 positions of the data in the file are "ITP", then rename the file as FileA_ITP, else if the first 3... (3 Replies)
Discussion started by: jchappel
3 Replies

5. Shell Programming and Scripting

Perl script to rename file,error

#!/usr/bin/perl $FL="ch.txt"; $CFL="mytext.txt"; print "This script will rename textfiles."; mv $FL $CFL; print "Done."; perl file.pl Error: Can't locate object method "mv" via package "ch.txt" (perhaps you forgot to load "ch.txt"?) at file.pl line 7. (5 Replies)
Discussion started by: cola
5 Replies

6. HP-UX

[Solved] Unable to rename file in ftp server .Net:FTP perl

Hello All, I am trying to connect to ftp server and get the files. Also i need to rename the file in other ftp dir. rename method is not allowing me to rename the file in other dir. When i tried copy command by using net::FTP:FILE then perl says it is not installed. Can some body help me to... (2 Replies)
Discussion started by: krsnadasa
2 Replies

7. UNIX for Dummies Questions & Answers

look for specific values in a file and rename file with value found

Hi, i have a file with some data ..look for some specific value in the file and if found that value rename the file with the value found in the file.. ex.. File.txt 1236 43715825601ANDERSSON, 1236 437158256031963040120060901200609010000000 1236 43715825604123 MCCL AVE UPPER 1236 ... (11 Replies)
Discussion started by: dssyadav
11 Replies

8. UNIX for Dummies Questions & Answers

awk - Rename output file, after processing, same as input file

I have one input file ABC.txt and one output DEF.txt. After the ABC is processed and created output, I want to rename ABC.txt to ABC.orig and DEF to ABC.txt. Currently when I am doing this, it does not process the input file as it cannot read and write to the same file. How can I achieve this? ... (12 Replies)
Discussion started by: High-T
12 Replies

9. Shell Programming and Scripting

Rename specific file extension in directory with match to another file in bash

I have a specific set (all ending with .bam) of downloaded files in a directory /home/cmccabe/Desktop/NGS/API/2-15-2016. What I am trying to do is use a match to $2 in name to rename the downloaded files. To make things a more involved the date of the folder is unique and in the header of name... (1 Reply)
Discussion started by: cmccabe
1 Replies

10. Shell Programming and Scripting

Bash to copy file 3 times and rename based on another file

In the below bash I am trying to copy the only text file (always only one) in /home/cmccabe/Desktop/list/QC/metrics.txt and rename each of the 3 text files according to /home/cmccabe/Desktop/test/list.txt using lines 3, 4 ,5. This format (that is list.txt) is always 5 lines. Thank you :). ... (12 Replies)
Discussion started by: cmccabe
12 Replies
File::Find::Rule::Perl(3)				User Contributed Perl Documentation				 File::Find::Rule::Perl(3)

NAME
File::Find::Rule::Perl - Common rules for searching for Perl things SYNOPSIS
use File::Find::Rule (); use File::Find::Rule::Perl (); # Find all Perl files smaller than 10k my @files = File::Find::Rule->perl_file ->size('<10Ki') ->in('dir'); # Locate all the modules that PAUSE will index my @mod = File::Find::Rule->no_index ->perl_module ->in('My-Distribution'); DESCRIPTION
I write a lot of things that muck with Perl files. And it always annoyed me that finding "perl files" requires a moderately complex File::Find::Rule pattern. File::Find::Rule::Perl provides methods for finding various types Perl-related files, or replicating search queries run on a distribution in various parts of the CPAN ecosystem. METHODS
perl_module The "perl_module" rule locates perl modules. That is, files that are named "*.pm". This rule is equivalent to "->"file->name( '*.pm' )> and is included primarily for completeness. perl_test The "perl_test" rule locates perl test scripts. That is, files that are named "*.t". This rule is equivalent to "->"file->name( '*.t' )> and is included primarily for completeness. perl_installer The "perl_installer" rule locates perl distribution installers. That is, it locates "Makefile.PL" and "Build.PL" files. perl_script The "perl_script" rule locates perl scripts. This is any file that ends in .pl, or any files without extensions that have a perl "hash-bang" line. perl_file The "perl_file" rule locates all files containing Perl code. This includes all the files matching the above "perl_module", "perl_test", "perl_installer" and "perl_script" rules. no_index # Provide the rules directly $rule->no_index( directory => [ 'inc', 't', 'examples' ], file => [ 'Foo.pm', 'lib/Foo.pm' ], ); # Provide a META.yml to use $rule->no_index( 'META.yml' ); # Provide a dist root directory to look for a META.yml in $rule->no_index( 'My-Distribution' ); # Automatically pick up a META.yml from the target directory $rule->no_index->in( 'My-Distribution' ); The "no_index" method applies a set of rules as per the no_index section in a "META.yml" file. SUPPORT
Bugs should always be submitted via the CPAN bug tracker <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=File-Find-Rule-Perl> For other issues, contact the maintainer AUTHOR
Adam Kennedy <adamk@cpan.org> SEE ALSO
<http://ali.as/>, File::Find::Rule, File::Find::Rule::PPI COPYRIGHT
Copyright 2006 - 2012 Adam Kennedy. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module. perl v5.16.3 2012-10-31 File::Find::Rule::Perl(3)
All times are GMT -4. The time now is 03:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy