- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: shell script
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
Forums
Discussions
Discussions
Forums
Discussions
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
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
07-17-2002 01:14 AM
07-17-2002 01:14 AM
-rw-r--r-- 1 apptst42 dba 1204 Jul 17 16:51 oo.r (file name)
I want to rename the file oo.r to oo.i. Don't
use copy and delete.
regards
ravi
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2002 01:17 AM
07-17-2002 01:17 AM
Re: shell script
use mv
hth
Patrick
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2002 01:17 AM
07-17-2002 01:17 AM
Re: shell script
Do the following
mv oo.r oo.i
-Sukant
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2002 01:17 AM
07-17-2002 01:17 AM
Re: shell script
#mv oo.r oo.i
regards,
U.SivaKumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2002 01:18 AM
07-17-2002 01:18 AM
Re: shell script
Just use mv
mv(1) mv(1)
NAME
mv - move or rename files and directories
SYNOPSIS
mv [-f|-i] [-e extarg] file1 new-file
mv [-f|-i] [-e extarg] file1 [file2 ...] dest-directory
mv [-f|-i] [-e extarg] directory1 [directory2 ...] dest-directory
DESCRIPTION
The mv command moves:
+ One file (file1) to a new or existing file (new-file).
Steve Steel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2002 01:23 AM
07-17-2002 01:23 AM
Re: shell script
i want to move the file oo.i to oo.r(example), actually
i don't know the file name but ending with .i
so how i will move the file *.i to *.r
regards
ravi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2002 01:29 AM
07-17-2002 01:29 AM
Re: shell script
for i in `ls`
do
echo "==== $i ===="
/usr/bin/mv $i oo.i
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2002 01:30 AM
07-17-2002 01:30 AM
Re: shell script
If there is a single file *.r this will work
#mv *.r oo.i
regards,
U.SivaKumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2002 01:32 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2002 01:42 AM
07-17-2002 01:42 AM
Re: shell script
Thanks lot, solved my problem.
i modified your script.
old=r
new=i
for file in `ls *.$old`
do
mv $file `echo $file | cut -d\. -f1`.$new
done
regards
ravi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2002 01:51 AM
07-17-2002 01:51 AM
Re: shell script
sorry,
Actually my requirment is i have 2 files
-rw-r--r-- 1 oratst42 dba 0 Jul 17 17:41 AS8@F2.20717.1741.I
-rw-r--r-- 1 oratst42 dba 870 Jul 17 17:50 AS8@10.20717.1750.I
but i ran that script i am getting output
like this
-rw-r--r-- 1 apptst42 dba 870 Jul 17 17:51 AS8@10.M
but i want like this
AS8@10.20717.1750.I to AS8@10.20717.1750.M
regards
ravi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2002 01:59 AM
07-17-2002 01:59 AM
Re: shell script
#!/sbin/sh
old=i
new=j
for file in *.$old
do
mv $file `echo $file | awk -F\. '{print $1"."$2"."$3"."}'`.$new
done
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2002 02:02 AM
07-17-2002 02:02 AM
Re: shell script
A better way:
Hi,
#!/sbin/sh
old=I
new=M
for file in *.$old
do
mv $file `echo $file | sed -e 's/.$old$/.$new/g'
done
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2002 02:04 AM
07-17-2002 02:04 AM
Re: shell script
I missed out a grave accent (`) after the sed:
#!/sbin/sh
old=I
new=M
for file in *.$old
do
mv $file `echo $file | sed -e 's/.$old$/.$new/g'`
done
With pattern matching (e.g. using sed), you do not need to worry about the number of dots (.) you have as part of your filename.
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2002 02:07 AM
07-17-2002 02:07 AM
Re: shell script
Again Thanks lot. All your scripts works fine
thanks. but I did this way.
old=I
new=M
for file in `ls *.$old`
do
mv $file `echo $file | cut -d\. -f1,2,3`.$new
done
regards
ravi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2002 03:30 AM
07-17-2002 03:30 AM
Re: shell script
Try the basename command for this
for file in *.I
do
mv $file `basename $file .I`.M
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2002 04:31 AM
07-17-2002 04:31 AM
Re: shell script
try the pattern-matching operators.
old=I
new=M
for file in `ls *.$old`
do
newfile=${file%.$old}.$new
mv $file $newfile
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2002 05:27 AM
07-17-2002 05:27 AM
Re: shell script
To replace the ending ".I" with ".M", use:
mv $ORIGINAL_FILE ${ORIGINAL_FILE%.I}.M
You do need to use the curly brackets.
Tom