- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- sed problems with "*"
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
08-27-2001 09:48 AM
08-27-2001 09:48 AM
sed problems with "*"
i?am a little bit confused about sed.
How can i cut away for example all the lines before the last ":" in one line.
For my Opionion, the following command should have as result: "Status READY" but sed does change no line ???
echo "ab:cd ef: READY" | sed s/ab*ef:/Status/g
Any ideas ???
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2001 10:21 AM
08-27-2001 10:21 AM
Re: sed problems with "*"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2001 10:27 AM
08-27-2001 10:27 AM
Re: sed problems with "*"
# echo "ab:cd ef: READY"|sed s/"ab:cd ef:"/Status/g
...will give the desired results.
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2001 10:42 AM
08-27-2001 10:42 AM
Re: sed problems with "*"
echo "ab:cd ef: READY" | sed 's/\(.*:\) .*$/\1Status/'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2001 10:50 AM
08-27-2001 10:50 AM
Re: sed problems with "*"
echo "ab:cd ef: READY" | sed 's/\(.*:\)\(:.*$\)/\1: Status/'
The string "\(.*:)" will match as much of the input string as possible. The result will be placed into "\1"
The string "\(:.*$\)" will match the end of the sting ($) back to the last ":"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2001 11:05 AM
08-27-2001 11:05 AM
Re: sed problems with "*"
echo "ab:cd ef: READY" | sed 's/\(.*\)\(:.*$\)/\1: Status/'
The string "\(.*\)" will match as much of the input string as possible. The result will be placed into "\1"
The string "\(:.*$\)" will match the end of the sting ($) back to the last ":"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2001 04:45 AM
08-28-2001 04:45 AM
Re: sed problems with "*"
In your specific example, you need a "." before the "*" to match any number of characters before "ef", i.e.
# echo "ab:cd ef: READY" | sed s/ab.*ef:/Status/g
Status READY
Rgds, Robin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2001 07:38 AM
08-28-2001 07:38 AM
Re: sed problems with "*"
this seems to be much easier with "awk":
echo "ab:cd ef: READY" | awk -F: '{print $NR;}'
The option "-F" sets the delimiter, and the
value of "$NR" (number of records) happens to
the number of the last field - which is the
rest of line after the last ":", of course ;-)
HTH,
Wodisch
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2001 08:14 AM
08-28-2001 08:14 AM
Re: sed problems with "*"
First I want to thank you for posting this question, because its been a great learning experience. And Robin, thanks, because I blew the question, I didn't see that he was trying to replace the string before the word "READY" with the word "Status".
This will work with all "status's":
echo "ab:cd ef: READY" | sed 's/\(.*:\)\(.*$\)/Status\2/'
Status READY
or
echo "ab: cd:ab ef: ABORTED" | sed 's/\(.*:\)\(.*$\)/Status\2/'
Status ABORTED
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2001 08:50 AM
08-28-2001 08:50 AM
Re: sed problems with "*"
First of all, as stated by Robin the '.' is needed before the '*'. The '*' matches and char is only valid when working with the shell and FNG (file name generation). In sed you work with regular expressions. And in regular expression the '*' is a quantifier for whatever it PRECEDES. So the '.' in '.*' says match one and only one char, and the '*' says any number of times.
Secondly, there is an issue of greediness. The '.*' will actually go to the end of line, therefore in you particular case you can simply
say:
echo "ab: cd:ab ef: ABORTED" |sed 's/.*:/Status/'
1) The .* goes to the end of line because the quantifiers are greedy.
2) The : requires a match
3) The regex engine BACKTRACKS until that point
4) Leaving you left what ever is after the LAST :
5) And ... the replacement part is quite simple now:)
Hope this helps.
Leslie