Grep-Find and Replace text inside <title> tag followed by change case

394 views
Skip to first unread message

Alex Santos

unread,
Nov 26, 2016, 9:34:00 AM11/26/16
to TextWrangler Talk
Hello

I have a long XML file with a boat load of <title></title> tags and the text within is in all uppercase.

I am trying to formulate a grep string to find and replace all text inside the <title> tag to Sentence Case or Upper Case for first letter only.

This is what I managed. Please be gentle with me as this is the first time I am even attempting to use grep. So far it selects the entire <title>*</title> line but when I try replace nothing really happens.

Find: \<title>([\w\s]+)</title>
Replace: \<title>\1\E\L\</title>

I included a screenshot of the find and replace window for Text Wrangler and a snippet of the text that I would like to replace, in this case it is between the <title> tags.








I would be grateful for any guidance.

Kindest regards
Alex Santos

Alex Santos

unread,
Nov 26, 2016, 10:43:35 AM11/26/16
to TextWrangler Talk
I've made some progress but I am missing one piece.

Find field: \<title>([\w\α\s]+)</title>

Replace field: \<title>\L\1\</title>

Here is what the above does. It finds the following line:

<title>POWIATOWY MIĘDZYSZKOLNY KONKURS BIBLIJNY W RADZYMINIE</title>

the results are: <title>powiatowy miĘdzyszkolny konkurs biblijny w radzyminie</title>

The character Ę is not made lower case.

Also, I would like the first character to remain uppercase, the p in 'powiatowy'.

Any help would be greatly appreciated.

Kind regards
—Alex

Thomas Fischer

unread,
Nov 28, 2016, 3:51:11 AM11/28/16
to textwr...@googlegroups.com
Dear Alex,

I can’t see how you can solve this using straight TW.
I use a Perl Script (easily called through Text -> Apply Text Filter).
On my machine the following will create something which looks like what you want:

#!/usr/bin/perl -w

binmode(STDIN, ":utf8");
binmode(STDOUT, ":utf8"); 

while(<>){
s/\b(.+?)\b/\u\L$1/g;
print;
}

You might need to add some locale directive, and you’ll have to anchor this with your title tags.

Cheers
Thomas


--
This is the TextWrangler Talk public discussion group.
If you have a feature request or would like to report a problem,
please email "sup...@barebones.com" instead of posting here.
---
You received this message because you are subscribed to the Google Groups "TextWrangler Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to textwrangler...@googlegroups.com.

Alex Santos

unread,
Nov 29, 2016, 8:51:41 AM11/29/16
to TextWrangler Talk
Hi Thomas

Thank you very much for taking the time to look into this. I will certainly try the perl script. I spent hours following up with manual corrections because I couldn't go beyond what I created with TW. Again, thank you for the time to develop the script and for taking the time to reply, I sincerely appreciate it.

Kindest regards
—Alex

Kimi Wei

unread,
Nov 29, 2016, 1:18:29 PM11/29/16
to textwr...@googlegroups.com
I’m looking for a way to save a clickable list of files I have opened in a text window, without keeping that window open. Is there a way to do that?

Kimi

Kimi Wei
ki...@thewei.com @kimiwei
facebook.com/thekimiwei
862-203-8814

Rich Siegel

unread,
Nov 29, 2016, 1:45:56 PM11/29/16
to textwr...@googlegroups.com
On Tuesday, November 29, 2016, Kimi Wei <kimi...@gmail.com> wrote:

>I’m looking for a way to save a clickable list of files I have opened
>in a text window, without keeping that window open. Is there a way to
>do that?

In BBEdit there is, yes. On the File menu, the "Save as Project"
command will do the job. (Projects are unique to BBEdit;
TextWrangler does not support them.)

R.
--
Rich Siegel Bare Bones Software, Inc.
<sie...@barebones.com> <http://www.barebones.com/>

Someday I'll look back on all this and laugh... until they
sedate me.

Patrick Woolsey

unread,
Nov 29, 2016, 2:05:28 PM11/29/16
to textwr...@googlegroups.com
On 11/29/16 at 11:53 AM, kimi...@gmail.com (Kimi Wei) wrote:

>I’m looking for a way to save a clickable list of files I
>have opened in a text window, without keeping that window open.
>Is there a way to do that?


Though TextWrangler does not have this capability, BBEdit allows
you to create & save project documents*, which you can use to
organize & quickly access groups of files. (* Along with many
other useful features. :-)

If you'd like to try this, you can download BBEdit 11 here:

<http://www.barebones.com/products/bbedit/demo.html>

BBEdit offers a 30-day evaluation period, and once that period
is over, it will continue working with a reduced feature set
which is still superior to TextWrangler's.

PS: If you have any feature-related questions while you're
evaluating BBEdit, please don't hesitate to contact us via <sup...@barebones.com>

Regards,

Patrick Woolsey
==
Bare Bones Software, Inc. <http://www.barebones.com/>

Reply all
Reply to author
Forward
0 new messages