[prev in list] [next in list] [prev in thread] [next in thread]
List: ubuntu-users
Subject: Regular Expression Puzzle
From: loic.grenie () gmail ! com (=?ISO-8859-1?Q?Lo=EFc_Greni=E9?=)
Date: 2009-11-30 7:11:41
Message-ID: 9b06e8d20911292311g4cbb57ddv2f1fed94adca5eef () mail ! gmail ! com
[Download RAW message or body]
2009/11/29 Ray Parrish <crp at 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 at 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 at 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
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic