On Tue, 2003-01-14 at 20:50, Cameron Simpson wrote:
> On 11:01 14 Jan 2003, Bret Hughes <[EMAIL PROTECTED]> wrote:
> | On Mon, 2003-01-13 at 13:18, Samuel Flory wrote:
> | > [EMAIL PROTECTED] wrote:
> | > >or try:
> | > >:g/abdfggg/s//opsmsdd/g from vi/vim
> | >
> | > That's really the hard way.
> | > :%s/abdfggg/opsmsdd/g works just as well and makes more sense.
> |
> | This is the vi syntax I am familier with. What is the first example
> | doing?
>
> It's a lesser known syntax, but valid all the way back to e and ed.
>
> It separates selection from operation. It says, "globally, for all lines
> containing abdfggg, substitute that (// being 'that') with opsmsdd".
>
> You can do more flexible things, like:
>
> g/foo/ .-2,.+2m0
> or
> g/bah/ s/this/that/g
>
Thanks Cameron,
If I understand correctly, your last example says for the entire file
look for lines that have bah, and if they do, subsitute all occurances
of this with that
Am I close? this is more flexible than trying to build a regex that
would do the same thing in the syntax I have used in the past. I never
have sucessfully atomized letter combinations so I can use ? as a
conditional. At least I don't think I have but I remember trying.
I remember trying something like (from memory only)
%s/({bah.*}?)(this)({.*bah}?)/$1that$3/g
I gave up when mozilla locked up with about 5 tabs open to various web
pages about regexes. I figured it was a sign. I don't remember what I
did instead probably a very inefficent perl script that at least let me
do the logic step by step.
the g/foo/ one I am going to have to read up on before beginning to ask
a question about it :)
Bret
--
redhat-list mailing list
unsubscribe mailto:[EMAIL PROTECTED]?subject=unsubscribe
https://listman.redhat.com/mailman/listinfo/redhat-list