Re: Sony CDs are not safe to play in a Windows computer
- From: Nobody <nobody@xxxxxxxxxxx>
- Date: Sat, 05 Nov 2005 07:42:08 +0000
On Sat, 05 Nov 2005 00:35:49 -0500, The Wanderer wrote:
>>>> OTOH, for most purposes I'd much rather use vi than sed.
>>>
>>> I use sed almost daily and vi never. sed is great when you need to
>>> replace some stuff in many files at once.
>>
>> That's what egrep is for... ^_^
>
> Out of curiosity, how? I've often wanted to do a search-and-replace from
> the command line, and my first instinct was to use grep, but I couldn't
> figure out how to tell it to do anything but print the line on which its
> result was found.
That's all it can do. You can't do search-and-replace with any of the grep
variants.
You normally either use sed's "s/old/new/g" or the equivalent in ed.
> I do tend to find egrep more useful than grep (just
> for versatility reasons), and I've usually managed to get my replacement
> jobs done with sed (except when they involve matching or outputting
> newlines, since sed doesn't seem to like those from the command
> line...),
Multi-line matches in sed are possible but slightly more involved. Each
command operates upon the pattern space, which normally only holds one
line of input at any time. To get around this:
First, use N to append the next line of input, which makes the pattern space
contain two lines of input separated by an embedded newline, which you can
match with \n. Then perform the modifications. Once you're done, use P
to print everything up to the newline and D to delete it and start the
next cycle. E.g. the command:
sed 'N;s/hello\( \|\n\)world/foo/;P;D'
will replace all occurrences of "hello world" with "foo", where the words
can be separated by either a space or a newline.
The "N;P;<something>;D" idiom is a common technique for ignoring newlines
when processing text.
.
- Follow-Ups:
- Re: Sony CDs are not safe to play in a Windows computer
- From: The Wanderer
- Re: Sony CDs are not safe to play in a Windows computer
- References:
- Re: Sony CDs are not safe to play in a Windows computer
- From: theslash1337
- Re: Sony CDs are not safe to play in a Windows computer
- From: sanjian
- Re: Sony CDs are not safe to play in a Windows computer
- From: Abraham Evangelista
- Re: Sony CDs are not safe to play in a Windows computer
- From: Sea Wasp
- Re: Sony CDs are not safe to play in a Windows computer
- From: Daniel Rudy
- Re: Sony CDs are not safe to play in a Windows computer
- From: Sea Wasp
- Re: Sony CDs are not safe to play in a Windows computer
- From: Rob Kelk
- Re: Sony CDs are not safe to play in a Windows computer
- From: ender
- Re: Sony CDs are not safe to play in a Windows computer
- From: Rob Kelk
- Re: Sony CDs are not safe to play in a Windows computer
- From: The Wanderer
- Re: Sony CDs are not safe to play in a Windows computer
- Prev by Date: Re: Sony CDs are not safe to play in a Windows computer
- Next by Date: Re: [OT] Since bashing Windows is in vogue right now...
- Previous by thread: Re: Sony CDs are not safe to play in a Windows computer
- Next by thread: Re: Sony CDs are not safe to play in a Windows computer
- Index(es):
Relevant Pages
|