Skip to ContentSkip to Footer
Start of content
General
-
- Forums
-
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
- HPE Blog, Austria, Germany & Switzerland
- Blog HPE, France
- HPE Blog, Italy
- HPE Blog, Japan
- HPE Blog, Middle East
- HPE Blog, Latin America
- HPE Blog, Russia
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
-
Blogs
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Blog, Latin America
- HPE Blog, Middle East
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
-
Information
- Community
- Welcome
- Getting Started
- FAQ
- Ranking Overview
- Rules of Participation
- Tips and Tricks
- Resources
- Announcements
- Email us
- Feedback
- Information Libraries
- Integrated Systems
- Networking
- Servers
- Storage
- Other HPE Sites
- Support Center
- Aruba Airheads Community
- Enterprise.nxt
- HPE Dev Community
- Cloud28+ Community
- Marketplace
-
Forums
-
Blogs
-
Information
-
English
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
- Email to a Friend
- 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
- Email to a Friend
- Report Inappropriate Content
01-09-2005 11:17 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- 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
- Email to a Friend
- 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.
End of content
United States
Hewlett Packard Enterprise International
Communities
- Communities
- HPE Blogs and Forum
© Copyright 2021 Hewlett Packard Enterprise Development LP