- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Regex sed issue
Operating System - HP-UX
1753762
Members
4822
Online
108799
Solutions
Forums
Categories
Company
Local Language
юдл
back
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
юдл
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
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
тАО06-04-2009 02:33 PM
тАО06-04-2009 02:33 PM
Hi All,
The following doesn't work on the command line-
#root@admin ]ls /cbo*/conf/hosts.conf | egrep -v '/cbo[^/]*\\.' | sed -e's/.*\\(cbo[^/]*\\)\\/.*/\\1/'
sed: -e expression #1, char 25: Unknown option to `s'
while it works if I pass the command to a variable-
hostsem=`ls /cbo*/conf/hosts.conf | egrep -v '/cbo[^/]*\\.' | sed -e's/.*\\(cbo[^/]*\\)\\/.*/\\1/'`
Please help as to why is that the case. What I need to do to make it work on the command line.
If you can elaborate on the regex after the sed -s that would be great as well.
Thanks,
Allan
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-04-2009 03:26 PM
тАО06-04-2009 03:26 PM
Solution
Hi Allan:
Reduce the double escape ('\\') to a single excape ('\') and the command works on the command line.
If you use the preferred Posix syntax instead of backticks, you get the same syntax error you see on the command line. That is, this fails:
# hostsem=$(ls /cbo*/conf/hosts.conf | egrep -v '/cbo[^/]*\\.' | sed -e's/.*\\(cbo[^/]*\\)\\/.*/\\1/')
I am not sure why the use of backticks makes this "work".
As for the 'sed' regular expression it looks for the sequence "cbo/" and if found it substitutes "cbo" for the whole line's sequence, printing the substition. The parenthezied part is what is captured and the \1 is a back-reference to the captured part. The [^/] means _not_ the "/" character. A dot is any character. A "*" means zero or more occurances of the preceding character.
Regards!
...JRF...
Reduce the double escape ('\\') to a single excape ('\') and the command works on the command line.
If you use the preferred Posix syntax instead of backticks, you get the same syntax error you see on the command line. That is, this fails:
# hostsem=$(ls /cbo*/conf/hosts.conf | egrep -v '/cbo[^/]*\\.' | sed -e's/.*\\(cbo[^/]*\\)\\/.*/\\1/')
I am not sure why the use of backticks makes this "work".
As for the 'sed' regular expression it looks for the sequence "cbo/" and if found it substitutes "cbo" for the whole line's sequence, printing the substition. The parenthezied part is what is captured and the \1 is a back-reference to the captured part. The [^/] means _not_ the "/" character. A dot is any character. A "*" means zero or more occurances of the preceding character.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-04-2009 05:12 PM
тАО06-04-2009 05:12 PM
Re: Regex sed issue
I would also use a different delimiter than "/". It appears that you aren't quoting the "/" in the brackets but it appears you don't need to?
But this is clearer:
's:.*\(cbo[^/]*\)\/.*:\1:'`
But this is clearer:
's:.*\(cbo[^/]*\)\/.*:\1:'`
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-04-2009 10:08 PM
тАО06-04-2009 10:08 PM
Re: Regex sed issue
Hi,
To know more about sed see the below link
http://www.ibm.com/developerworks/linux/library/l-sed1.html
http://www.ibm.com/developerworks/linux/library/l-sed2.html
Suraj
To know more about sed see the below link
http://www.ibm.com/developerworks/linux/library/l-sed1.html
http://www.ibm.com/developerworks/linux/library/l-sed2.html
Suraj
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.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP