Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Applications / Mac Applications / May 2008



Tip: Looking for answers? Try searching our database.

GREP pattern wanted

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Patricia Aldoraz - 24 May 2008 11:30 GMT
In Textwrangler or BBEdit what would be a GREP pattern to replace
either of two words with specific words depending on which word was
found? For example, I want the word "red" replaced with "crimson" and
also want "gray" replaced by "grey". How to make one pattern to get
this in one pass. It is easy to make two and have two passes. In other
words, what would have to be put into the Search for box and what in
the Replace with box?
Link - 24 May 2008 15:21 GMT
> In Textwrangler or BBEdit what would be a GREP pattern to replace
> either of two words with specific words depending on which word was
[quoted text clipped - 3 lines]
> words, what would have to be put into the Search for box and what in
> the Replace with box?

It is a lot easier to do it in two passes.  Is there any reason you
need to do it in one pass?
Signature

-L

dorayme - 25 May 2008 01:38 GMT
> > In Textwrangler or BBEdit what would be a GREP pattern to replace
> > either of two words with specific words depending on which word was
[quoted text clipped - 6 lines]
> It is a lot easier to do it in two passes.  Is there any reason you
> need to do it in one pass?

Perhaps she is wanting to do this sort of thing a lot and doing it in
two passes comes to double the effort. In BBedit at least, one can save
patterns. But to get to them one sometimes needs to scroll. To do this
twice, to slightly different patterns and repeatedly is obviously more
work.

But I agree that if it is just the odd one off, much much easier to do
it in two swoops than to spend time tooling up and well, basically
w.nking.

A case from my own experience is where I need to replace html mark-up
inside code tags where I need to be exhibiting source on the web page.
It would be a bore making two passes to replace the "<" and ">" each
time with respectively "&lt;" and "&gt;".

I get by these days with one search pattern and replace, which seems to
work:

Find: <([^<>]+)>

Replace: \&lt;\1\&gt;

but this is a special case.

Signature

dorayme

Wes Groleau - 25 May 2008 22:49 GMT
> I get by these days with one search pattern and replace, which seems to
> work:
[quoted text clipped - 4 lines]
>
> but this is a special case.

and doesn't work when certain typos occur.  :-)

Signature

Wes Groleau
   "If it wasn't for that blasted back-hoe,
    a hundred of us could be working with shovels"
   "Yeah, and if it weren't for our shovels,
    a thousand of us could be working with spoons."

dorayme - 26 May 2008 02:35 GMT
> > I get by these days with one search pattern and replace, which seems to
> > work:
[quoted text clipped - 6 lines]
>
> and doesn't work when certain typos occur.  :-)

It works well enough for my purposes (but then I am not subject to
normal human errors such as typos).

But you are welcome to elaborate with details.

Signature

dorayme

Link - 24 May 2008 15:27 GMT
> In Textwrangler or BBEdit what would be a GREP pattern to replace
> either of two words with specific words depending on which word was
[quoted text clipped - 3 lines]
> words, what would have to be put into the Search for box and what in
> the Replace with box?

If your file is plain text (which I'd assume it is, since you're
editing in TextWrangler), you can always pass it through sed: sed -e
's/red/crimson/g;s/gray/grey/g' test.txt
Signature

-L

Patricia Aldoraz - 25 May 2008 05:21 GMT
> If your file is plain text (which I'd assume it is, since you're
> editing in TextWrangler), you can always pass it through sed: sed -e
> 's/red/crimson/g;s/gray/grey/g' test.txt

Can you say more about this please?  Starting with I am looking at a
Textwrangler plain text file and I get something called sed and pass
something through it...
Barry Margolin - 25 May 2008 05:25 GMT
In article
<0695c2e1-17fb-4b42-917a-c9ca9f0bfb9d@a32g2000prf.googlegroups.com>,

> > If your file is plain text (which I'd assume it is, since you're
> > editing in TextWrangler), you can always pass it through sed: sed -e
[quoted text clipped - 3 lines]
> Textwrangler plain text file and I get something called sed and pass
> something through it...

You save the file to disk, then open a Terminal window, and type:

sed 's/red/crimson/g;s/gray/grey/g' filename.txt > filename-new.txt

Now filename-new.txt is the version with all the substitutions.

Signature

Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.