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
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
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
тАО03-12-2008 08:05 AM - last edited on тАО01-06-2013 01:00 AM by Maiko-I
тАО03-12-2008 08:05 AM - last edited on тАО01-06-2013 01:00 AM by Maiko-I
/usr/local/tomcat_staged_war_files/web_serv_8080/TestResults_WS_08120309.war
Given the above string, how do I substitute the _08120309 resulting in:
/usr/local/tomcat_staged_war_files/web_serv_8080/TestResults_WS.war
Also, How would I use 'find' to only find a file that contains this (_08120309) convention? This is a date string and is variable but alwas a '_' followed by 8 digits.
Thanks !
Mike
P.S. this thread has been moved from Insight Remote Support>general to Linux > sysadmin - HP Forums Moderator
Solved! Go to Solution.
- Tags:
- regex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-12-2008 08:22 AM
тАО03-12-2008 08:22 AM
Re: Regex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-12-2008 08:23 AM
тАО03-12-2008 08:23 AM
SolutionF="/usr/local/tomcat_staged_war_files/web_serv_8080/TestResults_WS_08120309.war"
# echo ${F}|perl -ple 's/_08120309//'
/usr/local/tomcat_staged_war_files/web_serv_8080/TestResults_WS.war
# cd /path && perl -MFile::Find -le 'find(sub{print if -f $_ && m/_\d{8}/},".")'
...The '\d' represents a digit and the '{8}' says eight of them, please.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-12-2008 08:25 AM
тАО03-12-2008 08:25 AM
Re: Regex
> Maybe the wrong forum. I am scripting in bash on redhat.
Well, Perl is universal :-)
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-13-2008 04:20 AM
тАО03-13-2008 04:20 AM
Re: Regex
echo $OLD | sed -e 's/_[0-9]\{8\}//'
# Assuming a "." after the numbers
find path -name "*_[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*"
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-13-2008 05:29 AM
тАО03-13-2008 05:29 AM
Re: Regex
Dennis, Sed is more my style, in fact I was trying to make that exact command work. Looks like all I needed were the quotes. What is the -e for? It works w/ or wo/ it. So, find and sed dont have the same regex capabilities, eh?
Thanks Guys !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-13-2008 05:31 AM
тАО03-13-2008 05:31 AM
Re: Regex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-13-2008 05:53 AM
тАО03-13-2008 05:53 AM
Re: Regex
Using -e allows you to have multiple scripts, same as grep. It is a good habit to get into.
>find and sed don't have the same regex capabilities, eh?
No. See regexp(5):
http://docs.hp.com/en/B2355-60130/regexp.5.html
sed/grep takes Basic Regular Expressions
find/ls/shells take Pattern Matching Notation
awk/egrep/grep -e take Extended Regular Expressions
perl takes the kitchen sink. :-)