Re: Yahoo! Groups: Welcome to sed-users. Visit today!

Joe Gain <[email protected]>
Newsgroups gmane.editors.sed.user
Message-ID <CAO6-GAfXiiv6WErsHaLbYWEAQQhk34vORAsNc-f8uGZdSQTaRg@mail.gmail.com>
Hi Luigi,

you need to take the time to look at how regular expressions are
built. When you are only copying an pasting it's very frustrating,
because you can't understand why something happens.

The first chapter in the regular expressions book from O'Reilly is a
really good start.

On Wed, Apr 25, 2012 at 8:06 PM, Luigi Assom <[email protected]> wrote:
> Joe, Cameron, thank you for your help!
>
> I did not know sed and tr command, they are totally new and the syntax
> really complex, and i don't know perl as well. I did not understand what
> you mean exactly, but I tried to copy the sytax you sent, barely as it is..
> the only thing which worked a bit seems to be this:
> sed -n -e 's/\(<a[^h]*href="\)\([^"]*\)"\([^>]*>\)/\2/g; p'
>
> so I was able to place the url inside the <a> tag outside which is good :)
> I could not split end of lines, because it is long text with no "\n"
> characters.

That's good if you have no newline characters. Sed is a _s_treem _ed_itor!

That's right, I would try and remove the surrounding tag (and
attributes) from the text that you want which is inside a tag. And
then remove all the other tags.

Perl is good because it gives you more control over your data. You can
also learn some basic perl pretty quickly.

>
> I just need to strip out all the other html tags (I don't need them) and
> keep only plain text outside the tags.
>
> so I will have a file like
> url texttext text text text text url text text text text text
> and then I should be ok to handle it.
>
> Maybe is there any GUI interface to use sed on mac?
> thank you for your help!

I don't know of any, maybe there is something online- a web
application, but I don't know.
>
> Luigi
>
> On Wed, Apr 25, 2012 at 12:14 AM, Cameron Simpson <[email protected]> wrote:
>
>> Joe has the truth here. I'm just adding a few remarks.
>>
>> On 24Apr2012 13:05, Joe Gain <[email protected]> wrote:
>> | one of sed's problems is dealing with newline characters
>>
>> Remark: specificly because it deals with a line at a time.
>>
>> | and you have
>> | your html anchor tags split over new lines. There's probably a smart
>> | way to overcome this using sed (and sed's line buffer), but it's not
>> | an easy alternative.
>> |
>> | I think the best way for you is to:
>> |
>> | 1. remove all the new line characters,or at least don't split tags
>> | with new lines (there are many ways to do this, depending on which
>> | version of sed you are using, could be as easy as # sed -n -e
>> | 's/\n//g; p' data.html)
>>
>> Or, not using sed:
>>
>>  ( tr -d '\012' < data.html ; echo ) | sed other-sed-work-now....
>>
>> This removes all the newlines using tr, then adds one at the end with
>> echo, thus putting all the text on a single line.
>>
>> personally I'd trn newlines into spaces, otherwise a word break across a
>> line like this:
>>
>>  <p> some words
>>  here</p>
>>
>> would become
>>
>>  <p> some wordshere</p>
>>
>> So:
>>
>>  ( tr '\012' ' ' < data.html ; echo ) | sed other-sed-work-now....
>>
>> Remember, sed is not your only tool.
>>
>> | 2. remove the surrounding tags from the text that you want in your
>> | anchor attributes with something like:
>> | sed -n -e 's/\(<a[^h]*href="\)\([^"]*\)"\([^>]*>\)/\2/g; p'
>>
>> I have my concerns here, specificly the "[^h]". It will match "<a href"
>> as intended, but it will also match all sorts of other undesired things.
>>
>>  <a  *href=
>>
>> is more reliable, matching spaces. It does presume no TAB characters.
>>
>> I would be inclined to use even more tr at the outset, to hammer the
>> text flatter:
>>
>>  ( tr '\011\012' ' ' < data.html ; echo ) | tr -s ' ' | sed ...
>>
>> So:
>>  - turn newlines and TABs into spaces
>>  - turn multiple spaces into a single space
>>
>> That way you can write patterns like this:
>>
>>  <a href=
>>
>> without having to cope with more than one space; it makes the regexps
>> much easier to write and read.
>>
>> Cheers,
>> --
>> Cameron Simpson <[email protected]> DoD#743
>> http://www.cskk.ezoshosting.com/cs/
>>
>> My venus fly trap is higher up the food chain than I am.
>>        - [email protected] (Simon Klyne)
>>
>
>
>
> --
> Luigi Assom
>
> Skype contact: oggigigi
>
>
> [Non-text portions of this message have been removed]
>
>
>
> ------------------------------------
>
> --
> Yahoo! Groups Links
>
>
>



-- 
joe gain

jacob-burckhardt-str. 16
78464 konstanz
germany

+49 (0)7531 60389

(...otherwise in ???)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.