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: 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: SOX ACQUIRE BURNETT, LOWELL, MOTA
    ... >>>Some people will think Mota was acquired for his potential. ... I suspect ... I had no idea you knew about sarcasm. ... Anyway, I did know about Lowell, ...
    (alt.sports.baseball.bos-redsox)
  • Re: Large cat, magic-user and clothing storage apparatus
    ... >> suspect this was the cause of the melted connector on the dipswitch/headlamp ... this one had overheated it's connector pins and melted the plug. ... a spare switch ex-burper and ditto connector with wires, ... I suspect there's the potential for cumulative damage in the connectors ...
    (uk.rec.sheds)