GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: delete 9 characters of filename (linux)
Operating System - Linux
1851659
Members
3729
Online
104061
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Knowledge Base
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
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
09-26-2006 09:01 PM
09-26-2006 09:01 PM
delete 9 characters of filename (linux)
I would like to delete 9 characters of filenames of different lengths: I use tcsh!!!
wsgsmax200011.nc
va925_199011.nc
va925_200011.nc
wss200011.nc
echo $file | cut -c 1-4: cuts the first 4 char.
I guess sed would be the right tool to do so:
echo $file | sed -e 's/[1,2].*nc//g'
works fine except for va925_200011.nc:
va9 instead of va925_
I guess I need a regular expression for the last 9 char.
cheers
Eric
wsgsmax200011.nc
va925_199011.nc
va925_200011.nc
wss200011.nc
echo $file | cut -c 1-4: cuts the first 4 char.
I guess sed would be the right tool to do so:
echo $file | sed -e 's/[1,2].*nc//g'
works fine except for va925_200011.nc:
va9 instead of va925_
I guess I need a regular expression for the last 9 char.
cheers
Eric
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2006 10:00 PM
09-26-2006 10:00 PM
Re: delete 9 characters of filename (linux)
The last 9 characters?
You need to use $ to anchor the match to the end of the string.
The simplest way would be:
echo $file | sed -e 's/.........$//g'
A bit more specific variant would be:
echo $file | sed -e 's/......\.nc//g'
You need to use $ to anchor the match to the end of the string.
The simplest way would be:
echo $file | sed -e 's/.........$//g'
A bit more specific variant would be:
echo $file | sed -e 's/......\.nc//g'
MK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2006 10:37 PM
09-26-2006 10:37 PM
Re: delete 9 characters of filename (linux)
thanks alot
it works perfectly!!!
it works perfectly!!!
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.
Company
Events and news
Customer resources
© Copyright 2026 Hewlett Packard Enterprise Development LP