- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- regular expression
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
03-15-2001 06:58 AM
03-15-2001 06:58 AM
i'm confused with an RE i've found in a script:
sed '/^{\\{/,/^}\\}/d'
Has anybody the expierience to explain me what this sed does ?
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2001 07:21 AM
03-15-2001 07:21 AM
Re: regular expression
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2001 07:23 AM
03-15-2001 07:23 AM
Re: regular expression
I recognize this one-liner is a bit complex: it prints all of input file (or echoed piped input) EXCEPT section between 2 regexp, knowing that regexp one is:
* line beginning with opening curly brace, followed by a backslash and immediately followed by another opening curly brace
and regexp 2 is:
* line beginning with closing curly brace, followed by a backslash and immediately followed by another closing curly brace.
So if your file looks like this:
--snip--
this is line 0
{\{ this is line 1
line 2
...
line n
}\} this is a trailling text
--snip--
then 'sed' output will give:
--snip--
this is line 1
line 2
...
line n
--snip--
I hope this helps !
Best regards,
Fred.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2001 07:30 AM
03-15-2001 07:30 AM
Re: regular expression
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2001 07:30 AM
03-15-2001 07:30 AM
Re: regular expression
I tried it...it will parse. But I can't figure out what it's supposed to do...it seems to violate some sed tructure even though it parses...I mean if you want to match in sed you'd \{ \} So I can't figure the second set of { } surrounding it because { } is awk not sed.
And that double \\ am I missing something--one \ means turns off the special meaning of the next character, which would negate the \{ \} sed match. The ^ says match the following at the beginning of the line, so what's that other ^ doing.
Oh my head.....I tried creating a file with some bogus lines starting with a variety of { / \ and so on...
You know what I got....
The statement parses ok...and produces a file with all my lines still in tact.
I'm going to find some excedrin now...I hope someone else had better results...
/rcw
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2001 07:35 AM
03-15-2001 07:35 AM
Re: regular expression
...so was the double backslash a carry-over for those of us who remember the now-defunct need to escape the backslash with itself in order to post to this forum???...so it would read (?):
# sed '/^{\{/,/^}\}/d'
with warm regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2001 07:35 AM
03-15-2001 07:35 AM
Re: regular expression
I used this testfile:
{\{dir
/dir/dir2/dir4
}\} /
/dir/dir2/dir5
/dir/dir2/dir6
{\{
And cat'ed it to that sed command:
# cat file | sed '/^{\\{/,/^}\\}/d'
/dir/dir2/dir5
/dir/dir2/dir6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2001 07:43 AM
03-15-2001 07:43 AM
Re: regular expression
Nope. Ugly. Double backslashes are correct. It won't parse otherwise. Should have tried it first ;-)
Great presentation of explanation, Fred!!!
Regards to all!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2001 07:47 AM
03-15-2001 07:47 AM
SolutionTo shed some light on this, let's take the following command:
sed '/Iowa/,/Montana/d'
Two regexp are denoted, which are strings "Iowa" and "Montana". sed finds these two strings and uses them as start and end delimiters (see the ending d command), printing whatever is between both (uh I hope you understand -- I'm afraid my english is not as good as I'd like it to be ;o))
--
Curly braces, when backslashed, match a range of occurrences of the single char that immediately precedes it. In Andreas' case, they are not backslashed but considered as curly braces.
--
Finally, you are right when saying that a single \ escapes the special char that follows, but if you want to match the char "backslash" (\), then you have to backslash it once more !
I attached to this post a file that contains many sed one-liners, including this one. I'm sure you'll find it useful.
HTH !
Fred.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2001 07:53 AM
03-15-2001 07:53 AM
Re: regular expression
Yes you're right. I even said it: "this sed command prints all of file EXCEPT section between two regexps", and i confused myself when replying:
--snip--
this is line 1
this is line 2
...
this is line n
--snip--
Of course, this is the opposit, ie:
--snip--
this is line 0
this is the trailing text
--snip--
Again, sorry for mistake! (Uh where is my AlkaSeltzer ?!)
Fred.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2001 08:05 AM
03-15-2001 08:05 AM
Re: regular expression
I would have never thought that this question would release as much.
Thank you for all the great responses.
Kind Regards
Andreas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2001 09:59 AM
03-15-2001 09:59 AM
Re: regular expression
Many Thanks - and you explained it well !
I am working at trying to improve my very basic sed & awk (much needed) skills...so things like this really help make me think.
And Thanks to Andreas for posting the challenge !
/rcw
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2001 10:22 AM
03-15-2001 10:22 AM
Re: regular expression
O'Reilly puts out what I have heard is a very good book on sed and awk. It is called 'SED & AWK' and it is one of the nutshell books that they put out. It is recommended to get at least the 2nd edition.
When I was at HP World in San Francisco in 1999, I attended a very good seminar on awk that David Totsch tought. I have a hard copy of the seminar handout, and it should be on the HP World CD, if I can find it. If you are interested let me know. (patrickwallek@upr.com)