- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Help in script
Operating System - HP-UX
1748265
Members
3990
Online
108760
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
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
- Report Inappropriate Content
тАО11-04-2009 08:34 AM
тАО11-04-2009 08:34 AM
I need to write a script which renames the files starting with XM and just take XM off their resulting names. For example, lets say there is a file called XMtest1.txt. The script will take XM off and rename this file to test1.txt and places it in the same working directory.
Any help will be highly appreciated.
Any help will be highly appreciated.
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-04-2009 08:42 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-04-2009 09:16 AM
тАО11-04-2009 09:16 AM
Re: Help in script
Hi Waqar,
You can also try this:
#!/usr/bin/sh
for FILE in `ll XM* | awk '{print$9}' | cut -c 3-`
do
mv XM${FILE} ${FILE}
done
You can also try this:
#!/usr/bin/sh
for FILE in `ll XM* | awk '{print$9}' | cut -c 3-`
do
mv XM${FILE} ${FILE}
done
Don't fix what ain't broke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-05-2009 03:01 AM
тАО11-05-2009 03:01 AM
Re: Help in script
>R.K.: You can also try this:
for FILE in `ll XM* | awk '{print$9}' | cut -c 3-`
There is no need to use ll(1) vs ls(1). The former is going to make the disk and NFS sweat by statting each file, you just want the name.
If you are already using awk, no need to use cut(1).
And you can improve on Patrick's sed by using a shell builtin:
for NAME in XM*; do
NEWNAME=${NAME#XM}
echo "${NAME} -- ${NEWNAME}"
mv ${NAME} ${NEWNAME}
done
If there is a chance there are no XM* files, you can do:
for NAME in $(ls XM* 2> /dev/null); do
NEWNAME=${NAME#XM}
echo "${NAME} -- ${NEWNAME}"
mv ${NAME} ${NEWNAME}
done
Or just add:
if [ "$NAME" = "XM*" ]; then break; fi
for FILE in `ll XM* | awk '{print$9}' | cut -c 3-`
There is no need to use ll(1) vs ls(1). The former is going to make the disk and NFS sweat by statting each file, you just want the name.
If you are already using awk, no need to use cut(1).
And you can improve on Patrick's sed by using a shell builtin:
for NAME in XM*; do
NEWNAME=${NAME#XM}
echo "${NAME} -- ${NEWNAME}"
mv ${NAME} ${NEWNAME}
done
If there is a chance there are no XM* files, you can do:
for NAME in $(ls XM* 2> /dev/null); do
NEWNAME=${NAME#XM}
echo "${NAME} -- ${NEWNAME}"
mv ${NAME} ${NEWNAME}
done
Or just add:
if [ "$NAME" = "XM*" ]; then break; fi
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.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP