- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Renaming Multiple files in one command
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
05-31-2005 02:55 PM
05-31-2005 02:55 PM
I have more that 500 file with naming convention
myfile.txt.20050117042157484.arc
and I want to rename them to
myfile.txt.20050117042157484
Want to remove ".arc" extension from all of them.
will this command do
ls -1 *.arc | awk '{print "mv "$1.arc" "$1" "}'
Thanks,
Amit.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2005 03:13 PM
05-31-2005 03:13 PM
Re: Renaming Multiple files in one command
Run this script on the directory of the file.
for i in `ll|grep txt|awk '{print $9}'`
do
nfile=${i%.arc}
mv $i $nfile
done
I checked it, it work. Modify to suit your needs.
Regards,
Paul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2005 05:12 PM
05-31-2005 05:12 PM
Re: Renaming Multiple files in one command
For example look for rename in a Unix faq:
http://www.faqs.org/faqs/unix-faq/faq/part2/index.html
The following examples, tailored to your problem work for me:
piping ls selection into perl:
$ ls my*arc | perl -ne 'chop; $old=$_; s/\.arc//; rename $old,$_'
or just perl glob function:
perl -e 'while (
btw... Paul's example can be simplified a lot replacing:
`ll|grep txt|awk '{print $9}'`
with:
`ls *txt*`
Regards,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2005 05:18 PM
05-31-2005 05:18 PM
Re: Renaming Multiple files in one command
try this ...
goto the directory where you want to change ....execute this ....
for i in *.arc
do
nfile=${i%.arc}
mv $i $nfile
done
I have checked and it works...
regds
Venkatesan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2005 05:18 PM
05-31-2005 05:18 PM
Re: Renaming Multiple files in one command
for file in `ls *.arc`
do
mv $file $(echo $file | cut -d"." -f1-3)
done
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2005 05:19 PM
05-31-2005 05:19 PM
Re: Renaming Multiple files in one command
ls -1 *.arc | awk '{ split($1,a,"."); print "mv "$1" "a[1]"."a[2]"."a[3] }' | sh
| sh is used to make action.
It will do it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2005 07:31 PM
06-01-2005 07:31 PM
Solutionfor f in *.arc
do
mv $f `basename $f .arc`
done
Or with find, to traverse a filesystem (this is a one-liner)
find . -name '*.arc' -exec 'mv {} `dirname {}`/`basename {} .arc` ;'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2005 08:51 PM
06-01-2005 08:51 PM
Re: Renaming Multiple files in one command
the following command will do what you're looking for...
# ls -1 *.arc | awk -F".arc" '{system("mv "$0" "$1)}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2005 11:51 PM
06-01-2005 11:51 PM
Re: Renaming Multiple files in one command
try this ,
ls -1 *arc |sed 's/\(.*\)\(\.arc\)/mv \1\2 \1'|sh -v
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2005 12:10 AM
06-02-2005 12:10 AM
Re: Renaming Multiple files in one command
sed -e 's/\.arc$//g'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2005 01:18 AM
06-02-2005 01:18 AM
Re: Renaming Multiple files in one command
The following will work for any extension
sed -e 's/\..*$//g'