9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] cut word out of a line with regexp
@ 2008-06-01 11:19 Matthias Teege
  2008-06-01 13:01 ` Russ Cox
  2008-06-01 13:05 ` Skip Tavakkolian
  0 siblings, 2 replies; 3+ messages in thread
From: Matthias Teege @ 2008-06-01 11:19 UTC (permalink / raw)
  To: 9fans

Moin!

How do I cut a word out of a line with sed? The word end with a '_'. I
don't know, how to match word boundaries. I need "sample"
out of a sample_ line.

Many thanks
Matthias




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [9fans] cut word out of a line with regexp
  2008-06-01 11:19 [9fans] cut word out of a line with regexp Matthias Teege
@ 2008-06-01 13:01 ` Russ Cox
  2008-06-01 13:05 ` Skip Tavakkolian
  1 sibling, 0 replies; 3+ messages in thread
From: Russ Cox @ 2008-06-01 13:01 UTC (permalink / raw)
  To: 9fans

> How do I cut a word out of a line with sed? The word end with a '_'. I
> don't know, how to match word boundaries. I need "sample"
> out of a sample_ line.

you can match word characters instead.

	sed 's/[^ ]+_ / /'
	sed 's/[a-zA-Z0-9_]+_([^a-zA-Z0-9_])/\1/'

russ



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [9fans] cut word out of a line with regexp
  2008-06-01 11:19 [9fans] cut word out of a line with regexp Matthias Teege
  2008-06-01 13:01 ` Russ Cox
@ 2008-06-01 13:05 ` Skip Tavakkolian
  1 sibling, 0 replies; 3+ messages in thread
From: Skip Tavakkolian @ 2008-06-01 13:05 UTC (permalink / raw)
  To: 9fans

> How do I cut a word out of a line with sed? The word end with a '_'. I
> don't know, how to match word boundaries. I need "sample"
> out of a sample_ line.

that blanks in the char class brackets are [ \t] (space and  tab)
you could expand the chars that can be part of a word, e.g. 0-9

cpuc% cat | sed 's/(^|[ 	]+)[A-Za-z][A-Za-z_]*_([ 	]+|$)/ /g'
this is a test_
this test_ is another
test_ this case too
test_test shouldn't get deleted
multiple test_ should also test_ work

\x04this is a
this is another
 this case too
test_test shouldn't get deleted
multiple should also work




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-06-01 13:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-01 11:19 [9fans] cut word out of a line with regexp Matthias Teege
2008-06-01 13:01 ` Russ Cox
2008-06-01 13:05 ` Skip Tavakkolian

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).