- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: change names of files
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
Discussions
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
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
01-17-2005 07:06 AM
01-17-2005 07:06 AM
I have to write a script which will replace all the files starting with letter 'F' to letter 'G'.
Can anyone please help me.
Thanks,
Rahul
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2005 07:11 AM
01-17-2005 07:11 AM
Re: change names of files
ls -1 | grep ^G >> file
while read -r rr
do
mv $rr $newname
done < file
You have to figure out what your renaming scheme is and make sure the variable $newname is filled.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2005 07:13 AM
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2005 07:16 AM
01-17-2005 07:16 AM
Re: change names of files
#!/usr/bin/sh
cd to desired starting directory:
find . -type f -name 'F*' | while read X
do
BASE=$(echo "${X}" | cut -c 2-)
NEW="G${BASE}"
if [[ -f "${NEW}" ]]
then
echo "File ${NEW} exists; skipping" >&2
else
mv "${X}" "${NEW}"
fi
done
Note that this tests for the existence of the replaced file before doing the actual mv. I would replace the mv command with a harmless 'echo "Moving ${X} to ${NEW}"' command for testing before doing the real thing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2005 07:19 AM
01-17-2005 07:19 AM
Re: change names of files
My requirement in that if i have the following files say
File1
File2
File3
in a directory. It should look like
Gile1
Gile2
Gile3
after the script is executed. All the files starting with letter 'F' should start with letter 'G'.
Thanks,
Rahul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2005 07:23 AM
01-17-2005 07:23 AM
Re: change names of files
If you want to do error checking, you probably have
to add a couple of lines to make sure that you are not
overwriting an existing file.
- Biswajit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2005 07:29 AM
01-17-2005 07:29 AM
Re: change names of files
ls F* | xargs -i echo X{} {}|sed -e "s/ F/ G/g" -e "s/^X/mv /" | sh
live free or die
harry d brown jr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2005 09:19 AM
01-17-2005 09:19 AM
Re: change names of files
# perl -e'map{($g=$_)=~s/^F/G/;`mv $_ $g}
TIMTOWTDI
Enjoy, Have FUN! H.Merijn
- Tags:
- Perl