FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Ubuntu > Ubuntu User

 
 
LinkBack Thread Tools
 
Old 11-29-2009, 08:22 PM
Ray Parrish
 
Default Regular Expression Puzzle

Hal Burgiss wrote:
> On Sun, Nov 29, 2009 at 09:53:09AM -0500, Alan McKay wrote:
>
>>> Those sample lines iI provided are from the navigation links I put at
>>> the top of all of my web pages, and it would be nice to do a broadcast
>>> change to update, or change their appearance instead pf having to edit
>>> every single file by hand, which takes hours.
>>>
>> You need a different approach to that problem - you should be using
>> generated pages
>>
>
> Even better, if I read the intent right as being a change to the look/feel of
> the document, is to use css, which is around for just the reason. Apply a
> 'class' to each like element, put a definition in the site's stylesheet, and
> then when you want a global change, you can do it with a one line edit to that
> css rule.
>
> Also, if there is some consistency to the markup, you can use jQuery to
> dynamically to it all:
>
> <script type="text/javascript">
> $("div a").css({'colorurple','background':'#ccc','fo nt-weight':'bold'});
> </script>
>
> which would handle any anchor tag that is a child of a div tag. jQuery will be
> more useful though with good use of css selectors in the markup itself.
>
I'm no stranger to using css and javascript to change the look of my web
site, I even have a page where my users can select the background image,
or color, and the text size they prefer while on my site.

That is part of the reason I wanted to have a block oriented multiple
document search and replace editor, as when I add a new "skin" to my web
site it necessitates that I add the new call to the new .css sheet on
every page on my site.

I also have a button bar at the top of every page which allows changing
the skins, and I need to add a new button, [i.e., table data cell with a
line of code] to every page as well when I add a new skin.

Thankfully, I have my multi-document, block oriented search and replace
program already written, so I'm good to go in that respect. I have some
small cosmetic things to iron out with it's Xdialog provided GUI
interface, and I haven't finished giving it the acid test to iron out
any unexpected surprises, but it is working quite well already.

I will be releasing it as open source software on my Ray's Links site
within the next couple of days, so have a look when it gets there. Any
web master will benefit from it's use. It is a little slow when handling
60 files all at once, but it is a bash script after all. 8-)

Later, Ray Parrish

--
The Future of Technology.
http://www.rayslinks.com/The%20Future%20of%20Technology.html
Ray's Links, a variety of links to usefull things, and articles by Ray.
http://www.rayslinks.com
Writings of "The" Schizophrenic, what it's like to be a schizo, and other
things, including my poetry.
http://www.writingsoftheschizophrenic.com



--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 11-29-2009, 08:27 PM
Kenneth Loafman
 
Default Regular Expression Puzzle

Ray Parrish wrote:
> Hello,
>
> I am trying to fathom a way to include a regular expression in a Search
> Term, and a Replace Term so that I can replace text strings that vary
> somewhat. For example, I have the following two lines in Test.html
>
> <div><a href="index.html">Ray's Links Home</a> / <a
> href="Science.html">Science</a> / Biology</div>
> <div><a href="index.html">Ray's Links Home</a> / <a href="Web
> Publishing.html">Web Publishing</a> / Web Editors</div>
>
> I would like to replace the <div>, and </div> tags with <p></p> for
> instance. What I did is -
>
> ray@RaysComputer:~/test$ FileContents=`cat Test.html`
> ray@RaysComputer:~/test$ SearchTerm="<div><a href="index.html">Ray's
> Links Home</a>*</div>"
> ray@RaysComputer:~/test$ ReplaceTerm="<p><a href="index.html">Ray's
> Links Home</a>*</p>"
> ray@RaysComputer:~/test$
> FileContents=${FileContents/$SearchTerm/$ReplaceTerm}
> ray@RaysComputer:~/test$ echo "$FileContents"
> <p><a href="index.html">Ray's Links Home</a>*</p>
> ray@RaysComputer:~/test$
>
> As you can see, it did not turn out quite how i wanted it to. I want to
> preserve everything between the <div></div> tags, and replace them with
> paragraph tags for this experiment.
>
> I thought the * in the SearchTerm, and ReplaceTerm would act as a
> wildcard, and preserve what was there, but it replaces it all with itself.
>
> Can anybody give me some guidance here?

1) don't try to do it in bash, the syntax is arcane at its best.
2) use something like sed -f and a regex file to do this like the
attached sed.example.sh and .log. I tried to quote it here, but the
line wrap makes things quite unreadable.

...Ken



--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 11-29-2009, 08:55 PM
Ray Parrish
 
Default Regular Expression Puzzle

Werner Schram wrote:
> Ray Parrish wrote:
>
>> Alan McKay wrote:
>>
>>
>>> Dude, that's a bit of a convoluted way to go about it.
>>>
>>> How about keeping it simple?
>>>
>>> cat file | sed "s/<div>/<p>/g" | sed "s/</div>/</p>/g" > newfile
>>>
>>>
>>>
>> Hello,
>>
>> I tried that command, and it does indeed change the <div>'s to <p>'s,
>> but it does it across the entire file, and I do not want to replace
>> every <div> in the file with paragraph tags.
>>
>> I need the ability to change certain blocks of text that are similar but
>> different in different files, and I would like a command that handles
>> all variations on the basic theme of it starts with a certain string,
>> varies in the middle, then is the same on the end of the string again.
>>
>> Those sample lines iI provided are from the navigation links I put at
>> the top of all of my web pages, and it would be nice to do a broadcast
>> change to update, or change their appearance instead pf having to edit
>> every single file by hand, which takes hours.
>>
>> Well, I'm back to reading up on regular exprssions to see if there is
>> some possible way to make a broadcast change through all of my pages to
>> change the appearance of the navigation links.
>>
>>
> Doing some reading is a good idea, regular expression can be extremely
> usefull. And being able to write undecipherable code that actually does
> what you want greatly boosts your l33t score
>
> In the mean time, I think this one is what you are looking for:
>
> sed "s,<div><a href="index.html">Ray's Links
> Home</a>(.*)</div>,<p><a href="index.html">Ray's Links
> Home</a>1</p>,g" file
>
> the inportant part is the (.*) in the search pattern and the 1 in the
> replace pattern. The brackets mean that you are grouping something to
> which you can reference back from the replace pattern using 1. The .
> matches any character and * means that you expect 0 or more of the
> previous character.
>
> Werner
>
Here is the result of running that command. I don't have a clue what is
wrong with the syntax, as I've never used sed before.

ray@RaysComputer:~/test$ sed "s,<div><a href="index.html">Ray's Links
Home</a>(.*)</div>;<p><a href="index.html">Ray's Links
Home</a>1</p>,g" Test.html
sed: -e expression #1, char 40: unterminated `s' command
ray@RaysComputer:~/test$

Thanks for helping, I would like to get this to work, so I guess I
better locate the sed documents and start studying them.

Later, Ray Parrish

--
The Future of Technology.
http://www.rayslinks.com/The%20Future%20of%20Technology.html
Ray's Links, a variety of links to usefull things, and articles by Ray.
http://www.rayslinks.com
Writings of "The" Schizophrenic, what it's like to be a schizo, and other
things, including my poetry.
http://www.writingsoftheschizophrenic.com



--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 11-29-2009, 09:04 PM
Ray Parrish
 
Default Regular Expression Puzzle

Werner Schram wrote:
> Ray Parrish wrote:
>
>> Alan McKay wrote:
>>
>>
>>> Dude, that's a bit of a convoluted way to go about it.
>>>
>>> How about keeping it simple?
>>>
>>> cat file | sed "s/<div>/<p>/g" | sed "s/</div>/</p>/g" > newfile
>>>
>>>
>>>
>> Hello,
>>
>> I tried that command, and it does indeed change the <div>'s to <p>'s,
>> but it does it across the entire file, and I do not want to replace
>> every <div> in the file with paragraph tags.
>>
>> I need the ability to change certain blocks of text that are similar but
>> different in different files, and I would like a command that handles
>> all variations on the basic theme of it starts with a certain string,
>> varies in the middle, then is the same on the end of the string again.
>>
>> Those sample lines iI provided are from the navigation links I put at
>> the top of all of my web pages, and it would be nice to do a broadcast
>> change to update, or change their appearance instead pf having to edit
>> every single file by hand, which takes hours.
>>
>> Well, I'm back to reading up on regular exprssions to see if there is
>> some possible way to make a broadcast change through all of my pages to
>> change the appearance of the navigation links.
>>
>>
> Doing some reading is a good idea, regular expression can be extremely
> usefull. And being able to write undecipherable code that actually does
> what you want greatly boosts your l33t score
>
> In the mean time, I think this one is what you are looking for:
>
> sed "s,<div><a href="index.html">Ray's Links
> Home</a>(.*)</div>,<p><a href="index.html">Ray's Links
> Home</a>1</p>,g" file
>
> the inportant part is the (.*) in the search pattern and the 1 in the
> replace pattern. The brackets mean that you are grouping something to
> which you can reference back from the replace pattern using 1. The .
> matches any character and * means that you expect 0 or more of the
> previous character.
>
> Werner
>
Success!!! It was the line feeds introduced by email that kept it from
working. Here is the output -

ray@RaysComputer:~/test$ sed "s,<div><a href="index.html">Ray's Links
Home</a>(.*)</div>,<p><a href="index.html">Ray's Links
Home</a>1</p>,g" Test.html

<p><a href="index.html">Ray's Links Home</a> / <a
href="Science.html">Science</a> / Biology</p>
<p><a href="index.html">Ray's Links Home</a> / <a href="Web
Publishing.html">Web Publishing</a> / Web Editors</p>

ray@RaysComputer:~/test$

Now all I have to do is figure out how to incorporate that into my multi
document editor program. 8-)

Later, Ray Parrish




--
The Future of Technology.
http://www.rayslinks.com/The%20Future%20of%20Technology.html
Ray's Links, a variety of links to usefull things, and articles by Ray.
http://www.rayslinks.com
Writings of "The" Schizophrenic, what it's like to be a schizo, and other
things, including my poetry.
http://www.writingsoftheschizophrenic.com



--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 11-30-2009, 06:11 AM
Loïc Grenié
 
Default Regular Expression Puzzle

2009/11/29 Ray Parrish <crp@cmc.net>:
> Werner Schram wrote:
>> In the mean time, I think this one is what you are looking for:
>>
>> sed "s,<div><a href="index.html">Ray's Links
>> Home</a>(.*)</div>,<p><a href="index.html">Ray's Links
>> Home</a>1</p>,g" file
>>
>> the inportant part is the (.*) in the search pattern and the 1 in the
>> replace pattern. The brackets mean that you are grouping something to
>> which you can reference back from the replace pattern using 1. The .
>> matches any character and * means that you expect 0 or more of the
>> previous character.
>>
>> Werner
>>
> Here is the result of running that command. I don't have a clue what is
> wrong with the syntax, as I've never used sed before.
>
> ray@RaysComputer:~/test$ sed "s,<div><a href="index.html">Ray's Links
> Home</a>(.*)</div>;<p><a href="index.html">Ray's Links
> Home</a>1</p>,g" Test.html
> sed: -e expression #1, char 40: unterminated `s' command
> ray@RaysComputer:~/test$
>
> Thanks for helping, I would like to get this to work, so I guess I
> better locate the sed documents and start studying them.

The problem are the and " in the " because both and " are
special to " (the ` and $ are also special in case you wondered).
You should try

sed 's,<div><a href="index.html">Ray's Links
Home</a>(.*)</div>;<p><a href="index.html">Ray's Links
Home</a>1</p>,g' Test.html

(the ' is special to ' so that I escaped them).

Loïc

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 

Thread Tools




All times are GMT. The time now is 02:13 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2007 - 2008, www.linux-archive.org