Re: sed: how do i do this?

From: Alan Connor (zzzzzz_at_xxx.yyy)
Date: 10/31/03


Date: Fri, 31 Oct 2003 05:29:49 GMT

On Thu, 30 Oct 2003 20:38:39 -0800, Lowell <lkirsh@cs.ubc.ca> wrote:
>
>
> First, I'm not sure sed is the best tool for the job, but I suspect it
> might be. Plus, I am trying to learn sed, so that'd be the preferred
> tool. I have a file and want to comment out part of it. I want specify a
> line (as a regular expression) and comment out every line after (and
> including) that line. The comment marker is 2 semi-colons at the
> beginning of each line.
>
> Thanks,
> Lowell
>
Try this, Lowell:

sed '/regex1/,/regex2/s/^.*$/;;&/' inputfile > tempfile
# make sure it worked, then finish up with
mv tempfile inputfile

(nothing wrong with marking the section with something easy like

XXX ZZZ , then doing the job and deleting those lines....)

s means "switch"

^ the beginning of the line

.* zero or more instances of any charcter

$ the end of the line

& the part of the line defined by the regex in the / / before

---------

for every line between regex1 and regex2, inclusive, switch the whole

line for ;; followed by the whole line. :-)

Sed's a great tool. The only good advanced tutorial I could find is
the OREILLY book, sed&awk 2nd Edition.

-- 
Alan C    this post ends with    w
                                 q


Relevant Pages

  • Re: Tech Needed: White Water optical sensor not working
    ... The ONLY switch that is not working is the 1 optical switch (Disaster ... test out, but I can't test the 2 chips, could these be ... If so, then yes, your 7 opto board would be suspect. ...
    (rec.games.pinball)
  • Re: 19" LCD recommendations please
    ... > I have absolutely no problems with a 19 inch gnr at 1280x1024, ... > switch it between a Linux box and a now rather elderly Acorn RiscPC ... never did work out why but I suspect it was a sort of inverted ...
    (uk.comp.homebuilt)
  • Sun Ultra 2 resetting itself (for your interest)
    ... The core dumps became more frequent to the point that they ... itself off - no core dump, it would just switch itself off. ... capacitors and tested them using a special ESR meter. ... a possibly suspect one, I ordered a new one and soldered it into the ...
    (comp.unix.solaris)
  • Re: GFloat Rounding issue in DEC Basic V1.2-000
    ... Yikes! ... I don't suspect any compiler bug, but have you tried the latest version ... you may need to switch from FLOAT to DECIMAL in certain places ...
    (comp.os.vms)
  • Re: [PATCH] fs/locks.c: prepare for BKL removal
    ... On Tuesday 21 September 2010 18:12:07 Sage Weil wrote: ... I suspect the easiest thing is to leave Ceph out of this stage of your ... I'll switch lock_kernelto lock_flocksonce that exists ...
    (Linux-Kernel)