Go to Google Groups Home  
Web    Images    Groups    News    Froogle    more »
  Advanced Groups Search
  Preferences    
View with framesSort by reply  Sorted by date
Messages 11-20 from thread "Sed question"
Prev 10   Next 10
Jump to [ Start of thread | End of thread ]

Message 11 in thread
From: John Rupley (rupley@arizona.edu)
Subject: Re: SED Question
 
View this article only
Newsgroups: comp.editors
Date: 1989-04-17 23:36:22 PST
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
Message 12 in thread
From: Dan Bernstein (bernsten@phoenix.Princeton.EDU)
Subject: Re: SED Question
 
View this article only
Newsgroups: comp.editors
Date: 1989-04-18 09:52:46 PST
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
Message 13 in thread
From: Woody Lee (woody@gergu2.tamu.edu)
Subject: Sed question
 
View this article only
Newsgroups: comp.editors
Date: 1994-03-09 15:26:23 PST
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)
Message 14 in thread
From: Otto Lind (otto@coactive.com)
Subject: Re: Sed question
 
View this article only
Newsgroups: comp.editors
Date: 1994-03-10 00:31:30 PST
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
Message 15 in thread
From: Hans Mulder (hansm@wsinti05.info.win.tue.nl)
Subject: Re: Sed question
 
View this article only
Newsgroups: comp.editors
Date: 1994-03-11 12:52:43 PST
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
Message 16 in thread
From: Soh Kam Hung (soh@demeter.trl.OZ.AU)
Subject: Re: Sed question
 
View this article only
Newsgroups: comp.editors
Date: 1994-03-14 15:08:07 PST
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
Message 17 in thread
From: dreeves@fix.net!nospam (dreeves@fix.net!nospam)
Subject: SED Question
 
View this article only
Newsgroups: comp.editors
Date: 1997/08/21
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
Message 18 in thread
From: Stan Brown (EDIT-THIS-OUTbrownsta@concentric.net)
Subject: Re: SED Question
 
View this article only
Newsgroups: comp.editors
Date: 1997/08/23
[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/
Message 19 in thread
From: Otavio Exel (oexel@economatica.com.br)
Subject: sed question
 
View this article only
Newsgroups: comp.editors
Date: 1998/01/02
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
Message 20 in thread
From: Kaz Kylheku (bill@cafe.net)
Subject: Re: sed question
 
View this article only
Newsgroups: comp.editors
Date: 1998/01/02
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