- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Need help writing a 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
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
11-24-2000 10:11 AM
11-24-2000 10:11 AM
I need to write a shell script that removes the characters given as the second argument from the end of the name of the file given as the first argument. So memo1.sv should rename memo1.sv to memo1.
Thanks for all your kind help!!!!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2000 10:51 AM
11-24-2000 10:51 AM
Re: Need help writing a shell script
A simple script with no error checking follows:-
#!/usr/bin/sh
FILE=${1}
SUFFIX=${2}
NEWFILE=${FILE%${SUFFIX}}
mv ${FILE} ${NEWFILE}
exit
Call it with:-
<scriptname>
Regards,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2000 11:32 AM
11-24-2000 11:32 AM
Re: Need help writing a shell script
#!/bin/sh
#
# renames without the last extension.
OLDNAME=$1
NEWNAME=` echo $OLDNAME | awk '{ n=split($1,filen,".")
for (i = 1; i < n ; i++ ) printf filen[i]"." }'`
mv $OLDNAME $NEWNAME
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2000 11:12 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2000 12:15 AM
11-27-2000 12:15 AM
Re: Need help writing a shell script
#/sbin/sh
mv $1 $(echo $1|sed 's/\(.*\)\..*$/\1/')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2000 06:12 AM
11-27-2000 06:12 AM
Re: Need help writing a shell script
#!/usr/bin/ksh
if [ $# = 0 ]; then
echo "Arg: fileSuffix"
exit
fi
MV=/tmp/mvSuff
echo 'mv $1 $(dirname $1)/$(basename $1 .'"$1"')' > $MV
chmod +x $MV
find . -name "*.$1" -exec $MV {} \;
rm $MV