- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Difficult string extraction
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
02-08-2017 07:40 AM
02-08-2017 07:40 AM
Hi,
Here the format of my filename
aaaaaaaaaaaaaaaaaaaaaaa.bbb.cccccccccccccc.gz
How to extract the 8 chars of the section just before .gz ?
Exemple:
SIEBER00_ora_38928476_1.aud.20170208163224.gz
=> 20170208
Any ideas ?
kind regards
Den.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2017 07:55 AM
02-08-2017 07:55 AM
Re: Difficult string extraction
If everything is the same format, then something like this may work:
# export VAR1=SIEBER00_ora_38928476_1.aud.20170208163224.gz # echo $VAR1 SIEBER00_ora_38928476_1.aud.20170208163224.gz # echo $VAR1 | awk -F . '{print $3}' | cut -c 1-8 20170208
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2017 08:20 AM - edited 02-08-2017 08:21 AM
02-08-2017 08:20 AM - edited 02-08-2017 08:21 AM
Re: Difficult string extraction
Hi, thank you for your answer,
I should have give more details. I can't check but perhaps I could have more . in the filename.
I missed to precise this and of course with your solution it works if format stays the same.
Is there a way to consider as a good mark the .gz and take the string before ? or it's too complicated ?
Kind regards,
Den
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2017 11:15 AM - edited 02-08-2017 11:15 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2017 12:10 PM
02-08-2017 12:10 PM
Re: Difficult string extraction
Or, if "sed" is your only friend:
pro3$ echo 'aaaa.aaa.bbb.c1c2c3c4c5c6c7.gz' | \
sed -e 's/^.*\.\([^.]*\)\.gz$/\1/' -e 's/\(........\).*/\1/'
c1c2c3c4
The first expression looks for any characters at the begininng {^.*},
a dot {\.}, any non-dot characters {[^.]*}, and ".gz" at the end
{\.gz$}, and keeps the non-dot characters between those dots (the last
dot before ".gz", and the dot in ".gz"). The second expression keeps
the first eight characters from that result.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2017 01:59 AM
02-09-2017 01:59 AM
Re: Difficult string extraction
Hi,
perfect, thank you.
Kind regards, Den.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2017 06:24 PM
02-11-2017 06:24 PM
Re: Difficult string extraction
You can of course program in awk:
echo "SIEBER00_ora_38928476_1.aud.20170208163224.gz" | awk '{print substr($0, index($0, ".gz") - 8, 8)}'