| Messages 11-20 from thread "Sed question" |
Prev 10 Next 10
Jump to [ Start of thread | End of thread ]
In article <99289@sun.Eng.Sun.COM>, jackh@sun.UUCP (John Hevelin) writes:
> This works for me. Put the following in a script
> and call with "sed -f script file"
[sed script deleted]
Seems like a buggy script -- for starters try it on:
xxxPROMPT>
>
<
PROMPT>
> PROMPT>
>
<
testing22
PROMPT>
>
Several previous postings handle such oddities, as does the Lex one-liner:
%%
^PROMPT>\n>\n<\n ;
John Rupley
rupley!local@megaron.arizona.edu
How about
(tr 'X\012' '\377X';echo '')
| sed 's/XPROMPTX<X>X/X/g'
| tr '\377X' 'X\012' | sed -n \$\!p
The echo '' to add a blank line and sed -n \$\!p to take it away
are necessary because sed can't handle input without a terminating
newline. The above commands will delete any three lines with exactly
PROMPT, <, and >; I don't remember if that was the original question
but this solution is much easier to generalize than the others given,
not to mention faster.
As usual, since we're dealing with sed, if your original input does not
end with a newline then the last line will disappear. If you're worried
about this, take away the sed -n \$\!p; then normal inputs will have an
extra line on the end and no-newline last lines will not be munched.
Of course, both tr and sed will munch nulls, and any 255's will be
changed to X's.
---Dan Bernstein, bernsten@phoenix.princeton.edu
I would like to include a new line in a substitution string.
IE:
sed 's/two/two\nspit/'
However the above command does not work. (if it did, I wouldn't be writing
this would I?)
Any help is greatly appreciated.
--
Woody Lee -=-=- woody@gergu2.tamu.edu -=-=- (409) 862-2321
GERG - Latex/A Data Office |"That's the whole problem with science.
Texas A&M University | You've got a bunch of empiricists trying
Department of Oceanography | to describe things of unimaginable wonder."
College Station, TX 77845 | - Calvin (& Hobbes)
Woody Lee (woody@gergu2.tamu.edu) wrote:
: I would like to include a new line in a substitution string.
:
: IE:
:
: sed 's/two/two\nspit/'
sed 's/two/two\^Jspit/'
To input the control J is dependent on your editor/shell (i.e. use ^V^M or
whatever).
Otto
--
Otto Lind Coactive Aesthetics
otto@coactive.com P.O. Box 425967, San Francisco, CA 94142
netcom!coactive!otto voice:(415)626-5152 fax:(415)626-6320
In <2llluv$c66@news.tamu.edu> woody@gergu2.tamu.edu (Woody Lee) writes:
>I would like to include a new line in a substitution string.
>sed 's/two/two\nspit/'
If you use a Bourne shell or compatible,
sed 's/two/two\
spit/'
will work. If you use a C shell, the command is
sed 's/two/two\\
spit/'
--
HansM
otto@coactive.com (Otto Lind) writes:
>Woody Lee (woody@gergu2.tamu.edu) wrote:
>: I would like to include a new line in a substitution string.
>: [ ... ]
>: sed 's/two/two\nspit/'
>sed 's/two/two\^Jspit/'
Since I usually have problems entering a newline in my shell, I do:
sed 's/two/two\\
spit' infile
Regards,
--
Soh Kam Hung, Network Management Research, | h.soh@trl.oz.au
TRL, POB 249 Clayton, Victoria 3168, Australia | +61 3 253 6638
I have a file I need to manipulate on regular basis. The rules of the
manipulation are this:
Column 61-85 on line 29 and every 42 lines therafter needs
to be cut and moved down 3 lines.
Columns 62-71 on line 32 and every 42 lines therafter needs to be
erased.
I looked at the cut and paste commands but I don't think they will do
what I want them to.
I'm thinking awk/sed will do what I want but I am not sure as I have
not used them before and the man pages are not the most helpful. (I
need lots of examples) Can anyone help me with this problem?
Cliff Campbell
dreeves@fix.net
[posted and emailed]
In article <33fcd1f7.99414431@news.supernews.com>, dreeves@fix.net!nospam
(dreeves@fix.net!nospam) wrote:
>I have a file I need to manipulate on regular basis. The rules of the
>manipulation are this:
>
>Column 61-85 on line 29 and every 42 lines therafter needs
>to be cut and moved down 3 lines.
I'm assuming you mean that it is appended to that point 3 lines down?
>Columns 62-71 on line 32 and every 42 lines therafter needs to be
>erased.
>
>I looked at the cut and paste commands but I don't think they will do
>what I want them to.
>
>I'm thinking awk/sed will do what I want
I don't think you even need sed. AWK should do the job. Something like
this:
NR%42 == 29 { fragment = substr($0,61,25)
print substr($0,1,60) substr($0,86)
next }
NR%42 == 32 { print substr($0,1,61) substr($0,72) fragment
next }
{print}
(The last line just prints all other lines normally.)
I'm away from my manual, so I may have made some syntax errors. In
particular, I can't remember whether string subscripts start at 1 or at 0
(embarrassing!). But this should give you the idea.
I've seen high praise for O'Reilly's sed/awk book, second edition only,
though I've not read the book myself.
--
Sorry for the inconvenience, but spam mails outnumbered real mails in
my box and I've been forced to edit my address. Please remove leading
capital letters if you wish to reply -- but don't send bulk email.
Stan Brown, Oak Road Systems, Cleveland, Ohio, USA
http://www.concentric.net/~Brownsta/
hi everybody,
is this the right NG for sed questions?
I want to find all lines beggining with a space, a plus sign or a minus
sign and insert 3 spaces *after* the first character; is there a better
way than:
s/^ / /
s/^+/+ /
s/^-/- /
beers,
--
Otavio Exel /<\oo/>\
oexel@economatica.com.br
In article <5B3B89E91E35208A.225DE97BE06ED112.5BC7E4307B87F8BB@library-proxy.airnews.net>,
Otavio Exel <oexel@economatica.com.br> wrote:
>
>hi everybody,
>
>is this the right NG for sed questions?
There is also alt.editors.batch or something like that, but it understandably
doesn't get much traffic. :)
>I want to find all lines beggining with a space, a plus sign or a minus
>sign and insert 3 spaces *after* the first character; is there a better
>way than:
>
>s/^ / /
>s/^+/+ /
>s/^-/- /
Yes, using a character class, and a replacement token which expands
to the matched text. That token is &
s/^[ +\-]/& /
as in vi.
Caveat: this works in GNU sed, but I don't have access to the POSIX
standard or a sed reference which would give me confidence that this
support for the vi-style & is a _standard_ sed feature.
Prev 10 Next 10
Jump to [ Start of thread | End of thread ]
©2004 Google