Re: sed: how do i do this?
From: Alan Connor (zzzzzz_at_xxx.yyy)
Date: 10/31/03
- Next message: Lowell: "Re: sed: how do i do this?"
- Previous message: Icarus Sparry: "Re: sed: how do i do this?"
- In reply to: Lowell: "sed: how do i do this?"
- Next in thread: Lowell: "Re: sed: how do i do this?"
- Reply: Lowell: "Re: sed: how do i do this?"
- Reply: Charles Demas: "Re: sed: how do i do this?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Lowell: "Re: sed: how do i do this?"
- Previous message: Icarus Sparry: "Re: sed: how do i do this?"
- In reply to: Lowell: "sed: how do i do this?"
- Next in thread: Lowell: "Re: sed: how do i do this?"
- Reply: Lowell: "Re: sed: how do i do this?"
- Reply: Charles Demas: "Re: sed: how do i do this?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|