- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- script rename files in dir. by stripping last 3 ch...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
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
Community
Resources
Forums
Blogs
- 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
тАО04-21-2004 08:23 AM
тАО04-21-2004 08:23 AM
=================
# ls
KEYA.SAM
Slyton.SAM
web_startfeb27.bup.SAM
WWW.SAM web.start.wand.sh.SAM
...
...
=====================
Need to be like:
KEYA
Slyton
web_startfeb27.bup
web.start.wand.sh
...
..
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-21-2004 08:33 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-21-2004 08:43 AM
тАО04-21-2004 08:43 AM
Re: script rename files in dir. by stripping last 3 characters
for FILE in /
do
mv ${FILE} $((basename ${FILE} .SAM))
done
Jeff Traigle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-21-2004 09:01 AM
тАО04-21-2004 09:01 AM
Re: script rename files in dir. by stripping last 3 characters
Jeff, I tried your script as well but
I get:
# for FILE in /home/paradigm/scripts/WED/*SAM
> do
> mv ${FILE} $((basename ${FILE} .SAM))
> done
ksh[3]: basename /home/paradigm/scripts/WED/KEYA.SAM .SAM: bad number
# x
jeff.It should work because I have seen other programmes use your login in their scripts. i will look at my syntax in ksh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-21-2004 09:18 AM
тАО04-21-2004 09:18 AM
Re: script rename files in dir. by stripping last 3 characters
Of course, I also realized that this assumes you're in the same directory as the files you're renaming since basename will strip the leading directory path if it exists. You could still keep the one-liner in there by putting a `dirname ${FILE}` in front of the `basename ${FILE} .SAM` probably. That just gets kind of verbose compared to the sed option though. :)
Jeff Traigle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-22-2004 02:04 AM
тАО04-22-2004 02:04 AM
Re: script rename files in dir. by stripping last 3 characters
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-22-2004 07:30 AM
тАО04-22-2004 07:30 AM
Re: script rename files in dir. by stripping last 3 characters
Jeff Traigle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-22-2004 09:00 AM
тАО04-22-2004 09:00 AM
Re: script rename files in dir. by stripping last 3 characters
Try:
for FILE in $DIR/*.SAM
do
mv $DIR/$FILE $DIR/${FILE%.SAM}
done
You can do a lot with that type of trick.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-26-2004 02:32 AM
тАО04-26-2004 02:32 AM
Re: script rename files in dir. by stripping last 3 characters
Nice suggestion but
I get the usage error message below when I run your script in ksh.
============================
-rw------- 1 root sys 440 Apr 21 16:00 web_startfeb27.SAM
-rw------- 1 root sys 442 Apr 21 16:00 web_startfeb27.bup.SAM
-rw-r--r-- 1 root sys 9 Apr 21 16:00 wed.SAM
-rw-r--r-- 1 root sys 0 Apr 21 16:00 wed.bup.SAM
potion:for FILE in $DIR/*.SAM
> do
> mv $DIR/$FILE $DIR/${FILE%.SAM}
> done
Usage: mv [-f] [-i] [-e warn|force|ignore] f1 f2
mv [-f] [-i] [-e warn|force|ignore] f1 ... fn d1
mv [-f] [-i] [-e warn|force|ignore] d1 d2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-26-2004 02:35 AM
тАО04-26-2004 02:35 AM
Re: script rename files in dir. by stripping last 3 characters
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-26-2004 02:36 AM
тАО04-26-2004 02:36 AM
Re: script rename files in dir. by stripping last 3 characters
Sorry, forgot the traiting }
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-26-2004 02:43 AM
тАО04-26-2004 02:43 AM
Re: script rename files in dir. by stripping last 3 characters
I get the substitution message below. I have perl 5.6.
Thanks
rw------- 1 root sys 442 Apr 21 16:00 web_startfeb27.bup.SAM
-rw-r--r-- 1 root sys 9 Apr 21 16:00 wed.SAM
-rw-r--r-- 1 root sys 0 Apr 21 16:00 wed.bup.SAM
potion:perl -MFile::Copy -e'for(@ARGV){($n=$_)=~s/\.sam$/i;move($_,$n)}' *.SAM *
.sam
Substitution replacement not terminated at -e line 1.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-26-2004 02:47 AM
тАО04-26-2004 02:47 AM
Re: script rename files in dir. by stripping last 3 characters
missing '/' before i
And of course perl was right :/
perl-5.6.x should do fine
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-26-2004 03:04 AM
тАО04-26-2004 03:04 AM
Re: script rename files in dir. by stripping last 3 characters
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-26-2004 03:11 AM
тАО04-26-2004 03:11 AM
Re: script rename files in dir. by stripping last 3 characters
> # perl -MFile::Copy
use module File::Copy. Present in all perl ports.
# man File::Copy for the manual page
> -e'
define the script
> for (@ARGV) {
for all command line arguments
> ($n = $_) =~ s/\.sam$//i;
set $n to the argument, and on the fly remove the .sam extension case insensitive (/i)
> move ($_, $n)
move () is from File::Copy, and does the same as unix' mv command, ut is safe accross OS's, so it'll also work on Win32, OS/2, and VMS
> }' *.SAM *.sam
and these are the command line arguments.
Enjoy, Have FUN! H.Merijn [ no magic involved this time. Only typo's :) ]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-26-2004 03:15 AM
тАО04-26-2004 03:15 AM