01-23-06 11:13 PM
On Mon, 23 Jan 2006 15:56:01 +0000 (UTC), Will Renkel
<renkel@xnet.com> wrote:
> the attached commands seem to do the job
> note it must be done TWICE to handle two successive "words with plus" that
are next to each other
> eg - kk abc+def hjy+kkk ll
> in the command the first -e sequence does internal words,
> the second does first word in line,
> and the third does last word in line.
>
> for first word, the word plus one space is deleted
> for last word space plus word is deleted
> for internal words word plus a space is deleted
>
> sed -e 's/ [^ ]*+[^ ]* / /g' -e 's/^[^ ]*+[^ ]* //' -e 's/
[^ ]*+[^ ]*$//' | sed -e 's/ [^ ]*+[^ ]* / /g' -e 's/^[
^ ]*+[^ ]* //' -e 's/ [^ ]*+[^ ]*$//'
>
>
You might simplify this by adding spaces to the beginning and end of
each line:
sed -e 's/.*/ & /' -e 's/ [^ ]*+[^ ]* / /g' -e 's/^ \(.*\) $/\1/'
To handle consecutive "x+y" words, you can use a loop:
sed -e 's/.*/ & /' -e ':loop;s/ [^ ]*+[^ ]* / /g;tloop' -e 's/^ \(.*
\) $/\1/'
Or as a sed script:
#!/bin/sed -f
s/.*/ & /
:loop
s/ [^ ]*+[^ ]* / /g
tloop
s/^ \(.*\) $/\1/
In most cases, use of these commands indicates that you are probably
better off programming in something like `awk' or Perl. But
occasionally one is committed to sticking with `sed', and these
commands can enable one to write quite convoluted scripts.
[from the GNU sed info file]
--
'Ooohh.. "FreeBSD is faster over loopback, when compared to Linux
over the wire". Film at 11.'
-- Linus Torvalds
[ Post a follow-up to this message ]
|