Operating System - Linux
1753424
Members
4791
Online
108793
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-09-2005 09:56 AM
тАО01-09-2005 09:56 AM
I have a bunch of files that I need to add a common pharse at the beginning of each file name. What command should I use to run this for a bunch of files?
e.g.
67898.txt
subject_67898.txt (I want to add subject to every file name)
Thanks
e.g.
67898.txt
subject_67898.txt (I want to add subject to every file name)
Thanks
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-09-2005 11:17 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-09-2005 03:26 PM
тАО01-09-2005 03:26 PM
Re: Help
Here is a classic perl script (with some examples to get you started) that I use for renaming files.
================================
#!/usr/bin/perl -w
# rename - rename files with a Perl expression
#
# This is a very short and simple but powerful script for renaming files.
# The script iterates through the @ARGV array and uses Perl's built-in
# rename function rename one file at a time according to a Perl statement
# that is entered by the user at the time the program is executed.
# The script uses eval to compile and execute a user-supplied string used
# to control renaming of the files.
#
#########################################################################
#
# Example 1
#
# rename 's/\.orig$//' *.orig
#
# Example 1 uses a substitute operator to change $_ and eliminate the
# string '.orig' appearing at the end of each file name.
#
#------------------------------------------------------------------------
#
# Example 2
#
# rename 'y/A-Z/a-z/ unless /^Make/' *
#
# Example 2 uses Perl's y operator to change all uppercase characters to
# lowercase characters in $_, with the trailing condition that this only
# be done if the file name starts with 'Make'.
#
#------------------------------------------------------------------------
#
# Example 3
#
# rename '$_ .= ".bad"' *.f
#
# Example 3 concatenates a '.bad' extention onto each file name.
#
#------------------------------------------------------------------------
#
# Example 4
#
# rename 'print "$_: "; s /foo/bar/ if
#
# Example 4 prompts the user with each file name abd reads the user response
# from the standard input. If the user's response starts with 'y' or 'Y',
# then a substitute operator changes 'foo' to 'bar' in the file name.
#
#------------------------------------------------------------------------
#
# Example 5
#
# find /tmp -name '*~' -print | rename 's|^(.*)/(.+)~$|$1/.#$2|'
#
# Example 5 demonstrates that the rename script can also receive its list
# of file names from via the standard input instead of through command line
# arguments. The find command is used to search for files under the /tmp
# directory whose names end with a '~'. These are backup files created by
# the emacs editor. The find command prints the pathnames to all such files
# and pipes this list of pathnames to the rename script. The rename script
# uses a substitute operator to capture everything in the file name leading
# up to the final '~' and renames the file with a '.#' prefix and no '~' at
# the end. For example a file called /tmp/d/myfile~ is renamed to
# /tmp/d/.#myfile
#
#------------------------------------------------------------------------
#
# use shift to extract the first command line argument - this is the string
# containing the Perl statement(s) to be compiled and executed.
# These Perl operations are stored in a $op variable.
($op = shift) || die "Usage: rename expr [files]\n";
chomp(@ARGV =
foreach (@ARGV) {
# save the current file name in $was
$was = $_; # $_ is the default loop variable
eval $op; # compile and execute the Perl
# operations submitted by the user
die if $@; # means eval 'failed'
rename($was, $_) unless $was eq $_; # rename is a Perl built-in function
}
================================
HTH,
Ross
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-09-2005 05:01 PM
тАО01-09-2005 05:01 PM
Re: Help
Thanks for the help!
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP