[CS-FSLUG] regexp help
Tim Young
Tim.Young at LightSys.org
Thu Nov 11 14:55:01 CST 2004
There are a zillion ways to do this. If all hyphens are used this way, the
simplest is:
cat [myfile] | sed 's/-/--/g'
If you are in vi., the same command is:
:%s/-/--/
But if you need to do it only when there is a worda-wordb, you can do this:
cat [myfile] | sed 's/([a-Z0-9][a-Z0-9]*)-([a-Z0-9][a-Z0-9]*)/\1--\2/g'
and in vi:
:%s/([a-Z0-9][a-Z0-9]*)-([a-Z0-9][a-Z0-9]*)/\1--\2/g
I believe these work. I am away from my linux box at the moment... :(
- Tim
Eduardo Sanchez wrote:
> People, I'm stuck in a rut, and I need the help of the regexp wizards
> here.
>
> I have some strings as follows:
>
> wordA-wordB
>
> That is, two words (or numbers, or practically any ASCII char) joined by
> a hyphen.
>
> What I would need to do is to perform a search and replace so that the
> above string is changed to:
>
> wordA--wordB
>
> that is, I need to search instances of a single hyphen and replace it
> with a double hyphen. I know there's some regexps I could use, but now
> I'm stuck and I don't know even where to begin.
>
> Any help will be greatly appreciated.
>
> Thanks in advance,
>
> Eduardo
>
> --
> Prof. Eduardo Sanchez
> Asuncion, Paraguay, South America
> --------------------------------------------------------------
> For "Is" and "Is-not" though with Rule and Line
> And "UP-AND-DOWN" by Logic I define,
> Of all that one should care to fathom, I
> was never deep in anything but--Wine.
>
> -- The Rubaiyat of Omar Khayyam
>
>
> --------------------------------------------------------------
>
> _______________________________________________
> ChristianSource FSLUG mailing list
> Christiansource at ofb.biz
> http://cs.uninetsolutions.com
More information about the Christiansource
mailing list