|
20-06-2008, 17:03 | #1 |
The list is long, but distinguished
Join Date: Dec 2006
Location: Århus, Denmark
Posts: 1,643
|
I Sed, she sed
Does anyone here use sed much? I've got a bit stuck, could do with some help!
__________________
|
20-06-2008, 17:03 | #2 |
Preparing more tumbleweed
Join Date: Jun 2006
Location: Hawaii
Posts: 6,038
|
Whatcha trying to achieve? I use it on and off here.
__________________
Mal: Define "interesting"? Wash: "Oh, God, oh, God, we're all gonna die"? |
20-06-2008, 17:07 | #3 |
The list is long, but distinguished
Join Date: Dec 2006
Location: Århus, Denmark
Posts: 1,643
|
Right, this is a simple example. In real times, my data is a bit hairy but the idea should work.
I have a file populated a little like this: abcdefghijklmn<<o>>pqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefg<h>ijklmnopqrstuvwxyz abcdefghijkl<<m>>nopqr<<s>>tuvwxyz abcdef<g>hijklmnopqrs<<t>>uvwxyz abcdefghijklmno<<p>>qrstuvwxyz I need to use sed to extract out anything surrounded by << >>. So ideally I'd end up with: o m s t p It's frustrating me somewhat.
__________________
|
20-06-2008, 20:30 | #4 |
Screaming Orgasm
Join Date: Jul 2006
Location: Newbury
Posts: 15,194
|
The fact you can have more than one pattern per line caused me some major grief, but if it's OK to use sed twice, then I managed to get around that one:
Code:
sed '/\(<<[^<>]*>>\)/s//\n\1\n/g' | sed '/^<<\([^<>]*\)>>$/s//\1/p;d' Last edited by Mark; 20-06-2008 at 20:35. |
20-06-2008, 20:40 | #5 |
The list is long, but distinguished
Join Date: Dec 2006
Location: Århus, Denmark
Posts: 1,643
|
Thanks Mark. I've not used sed much, takes some getting used to.
__________________
|
07-10-2008, 10:09 | #6 | |
The list is long, but distinguished
Join Date: Dec 2006
Location: Århus, Denmark
Posts: 1,643
|
Quote:
Code:
abcdefgh<<ijklmno>pqrst>>uvwxyz abcdefgh<<ijklmno<pqrst>>uvwxyz
__________________
|
|
20-06-2008, 20:43 | #7 |
Screaming Orgasm
Join Date: Jul 2006
Location: Newbury
Posts: 15,194
|
Make sure you use the latest edit - I spotted a few bits of redundant code in the original and removed them.
|
20-06-2008, 23:26 | #8 | |
Rocket Fuel
Join Date: Jun 2006
Location: Adrift in the Orca
Posts: 6,845
|
Quote:
__________________
We must move forward not backward, upwards not forward, and always twirling, twirling, twirling... |
|
21-06-2008, 03:13 | #9 |
Screaming Orgasm
Join Date: Jul 2006
Location: Newbury
Posts: 15,194
|
I do wonder what that would say when translated into semaphore and back.
Last edited by Mark; 21-06-2008 at 03:45. |
23-06-2008, 15:34 | #10 |
The list is long, but distinguished
Join Date: Dec 2006
Location: Århus, Denmark
Posts: 1,643
|
OK, second challange. This should be easy, I've nearly got it working but seem to be running in circles.
Say you have this: Code:
{.One$="One",.Number=12,.Two$="Two",.Number=13,.Three$="Three",/ A pint to whoever digs me out of sed hell #2. I really should buy a book on this...
__________________
|