- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Renaming lots 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
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
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
04-21-2020 03:02 AM - last edited on 04-27-2020 02:12 AM by Parvez_Admin
04-21-2020 03:02 AM - last edited on 04-27-2020 02:12 AM by Parvez_Admin
I have a folder on my hp-ux 11.31, with lots of files with long filename, and I just want the the filename to have the first 20 characters and add an extension.txt
The piece of code I am trying is giving me an error:
for file in /path/to/directory/*; do
echo mv –i “$file “ “${file:0:20}.txt”
done
But I am having the following error:
sh test.sh
test.sh[2]: "${file:0:20}.txt": The specified substitution is not valid for this command
Any hint on what might be wrong
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2020 05:48 AM
04-21-2020 05:48 AM
Re: Renaming lots of files
> But I am having the following error:
What is "${file}"? Does the expression fail on the first name, or on
some particular name?
Which shell?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2020 06:33 AM
04-21-2020 06:33 AM
Re: Renaming lots of files
Hi
it fails on the very first name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2020 09:31 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2020 12:03 AM
04-22-2020 12:03 AM
Re: Renaming lots of files
> [...] cut -c 1-20)
But then I'd need to remember that "cut" exists. As I always say,
"If you can't do it with 'sed', then it's not worth doing."
$ echo 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\(.\{20\}\).*/\1/'
abcdefghijklmnopqrst
(And it's so much clearer.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2020 03:58 AM
04-22-2020 03:58 AM
Re: Renaming lots of files
Substring expansion is a capability of the bash shell - it is not available in the POSIX shell which is the default shell used on HP-UX. You could install bash and use that if you wanted this to work in the way you outlined. Otherwise you've been provided with some alternatives that work on HP-UX using sh and cut and/or sed (if you like explosions in punctuation factories)
bash and its runtime dependencies on HP-UX are available here: http://hpux.connect.org.uk/hppd/hpux/Shells/bash-5.0.016/
I am an HPE Employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2020 03:40 AM
04-23-2020 03:40 AM
Re: Renaming lots of files
Thanks a lot your contribution was perfect!