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 > Redhat > Fedora User

 
 
LinkBack Thread Tools
 
Old 02-27-2010, 04:12 PM
Vadkan Jozsef
 
Default perl or bash question

How can I do that in bash or perl, that I have a txt file, e.g.:

$cat file.txt
Hi, this is the content of the txt file, that contains links like this:
http://www.somewhere.it/, and it could contain: http://somewhere.com,
etc..
This is the second line, that doesn't contains links..
..
This is the XYZ line, that contains a link: http://www.somewhere.net
$


...ok.. so how could I make a regexp for this?

Turning:

http://website.org
http://www.website.org

to this:

<a href=http://website.org>http://website.org</a>
<a href=http://www.website.org>http://www.website.org</a>

The solution would be:

sed 'SOMEMAGIC' file.txt > file.html
or
perl 'SOMEBIGMAGIC' file.txt > file.html




--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 1267290722.2365.12.camel@ubuntu">http://lists.debian.org/1267290722.2365.12.camel@ubuntu
 
Old 02-27-2010, 04:12 PM
Vadkan Jozsef
 
Default perl or bash question

How can I do that in bash or perl, that I have a txt file, e.g.:

$cat file.txt
Hi, this is the content of the txt file, that contains links like this:
http://www.somewhere.it/, and it could contain: http://somewhere.com,
etc..
This is the second line, that doesn't contains links..
..
This is the XYZ line, that contains a link: http://www.somewhere.net
$


...ok.. so how could I make a regexp for this?

Turning:

http://website.org
http://www.website.org

to this:

<a href=http://website.org>http://website.org</a>
<a href=http://www.website.org>http://www.website.org</a>

The solution would be:

sed 'SOMEMAGIC' file.txt > file.html
or
perl 'SOMEBIGMAGIC' file.txt > file.html




--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 02-27-2010, 04:12 PM
Vadkan Jozsef
 
Default perl or bash question

How can I do that in bash or perl, that I have a txt file, e.g.:

$cat file.txt
Hi, this is the content of the txt file, that contains links like this:
http://www.somewhere.it/, and it could contain: http://somewhere.com,
etc..
This is the second line, that doesn't contains links..
..
This is the XYZ line, that contains a link: http://www.somewhere.net
$


...ok.. so how could I make a regexp for this?

Turning:

http://website.org
http://www.website.org

to this:

<a href=http://website.org>http://website.org</a>
<a href=http://www.website.org>http://www.website.org</a>

The solution would be:

sed 'SOMEMAGIC' file.txt > file.html
or
perl 'SOMEBIGMAGIC' file.txt > file.html



--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
 
Old 02-27-2010, 04:16 PM
CLIFFORD ILKAY
 
Default perl or bash question

On 02/27/2010 12:12 PM, Vadkan Jozsef wrote:
> How can I do that in bash or perl, that I have a txt file, e.g.:
>
> $cat file.txt Hi, this is the content of the txt file, that contains
> links like this: http://www.somewhere.it/, and it could contain:
> http://somewhere.com, etc.. This is the second line, that doesn't
> contains links.. .. This is the XYZ line, that contains a link:
> http://www.somewhere.net $

You could take a look at the source for
<http://docs.djangoproject.com/en/1.1/ref/templates/builtins/#urlize>
and see how it's done in Python and extrapolate from there.
--
Regards,

Clifford Ilkay
Dinamis
1419-3266 Yonge St.
Toronto, ON
Canada M4N 3P6

<http://dinamis.com>
+1 416-410-3326

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 02-27-2010, 04:31 PM
Russell Miller
 
Default perl or bash question

On Saturday 27 February 2010 09:12:06 Vadkan Jozsef wrote:
> How can I do that in bash or perl, that I have a txt file, e.g.:
>
something like

sed -ie s/(.*)/<a href="1">1</a>/ filename

Not sure of the EXACT syntax but that should be close.

(apologies if this gets sent twice, I sent the first from the wrong address)

--Russell
--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
 
Old 02-27-2010, 04:36 PM
Tony van der Hoff
 
Default perl or bash question

On 27/02/10 17:12, Vadkan Jozsef wrote:

How can I do that in bash or perl, that I have a txt file, e.g.:

$cat file.txt
Hi, this is the content of the txt file, that contains links like this:
http://www.somewhere.it/, and it could contain: http://somewhere.com,
etc..
This is the second line, that doesn't contains links..
..
This is the XYZ line, that contains a link: http://www.somewhere.net
$


...ok.. so how could I make a regexp for this?

Turning:

http://website.org
http://www.website.org

to this:

<a href=http://website.org>http://website.org</a>
<a href=http://www.website.org>http://www.website.org</a>

The solution would be:

sed 'SOMEMAGIC' file.txt> file.html
or
perl 'SOMEBIGMAGIC' file.txt> file.html



Hmm, hardly on-topic for this list, but doubtless someone will want to
show off their regex skills.


Just to convince us that you're not asking us to do your homework for
you, what have you tried so far, wit what results?


--
Tony van der Hoff | mailto:tony@vanderhoff.org
Buckinghamshire, England |


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org

Archive: 4B895829.3070500@vanderhoff.org">http://lists.debian.org/4B895829.3070500@vanderhoff.org
 
Old 02-27-2010, 04:40 PM
Alex Janssen
 
Default perl or bash question

Vadkan Jozsef wrote:
> How can I do that in bash or perl, that I have a txt file, e.g.:
>
> $cat file.txt
> Hi, this is the content of the txt file, that contains links like this:
> http://www.somewhere.it/, and it could contain: http://somewhere.com,
> etc..
> This is the second line, that doesn't contains links..
> ..
> This is the XYZ line, that contains a link: http://www.somewhere.net
> $
>
>
> ...ok.. so how could I make a regexp for this?
>
> Turning:
>
> http://website.org
> http://www.website.org
>
> to this:
>
> <a href=http://website.org>http://website.org</a>
> <a href=http://www.website.org>http://www.website.org</a>
>
> The solution would be:
>
> sed 'SOMEMAGIC' file.txt > file.html
> or
> perl 'SOMEBIGMAGIC' file.txt > file.html
>
>
>
grep -io "<a.*</a>" somefile.html
That'll extract just the href code.

Alex

--
Ourwoods.org
Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. - Albert Einstein (275)


--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 02-27-2010, 04:52 PM
Kelly Clowers
 
Default perl or bash question

On Sat, Feb 27, 2010 at 09:12, Vadkan Jozsef <jozsi.avadkan@gmail.com> wrote:
> How can I do that in bash or perl, that I have a txt file, e.g.:
>
> $cat file.txt
> Hi, this is the content of the txt file, that contains links like this:
> http://www.somewhere.it/, and it could contain: http://somewhere.com,
> etc..
> This is the second line, that doesn't contains links..
> ..
> This is the XYZ line, that contains a link: http://www.somewhere.net
> $
>
>
> ...ok.. so how could I make a regexp for this?
>
> Turning:
>
> http://website.org
> http://www.website.org
>
> to this:
>
> <a href=http://website.org>http://website.org</a>
> <a href=http://www.website.org>http://www.website.org</a>
>
> The solution would be:
>
> sed 'SOMEMAGIC' file.txt > file.html
> or
> perl 'SOMEBIGMAGIC' file.txt > file.html

You might look at the brand new Bleach python library:
http://coffeeonthekeyboard.com/bleach-html-sanitizer-and-auto-linker-for-django-344/

That post mentions some of the problems of using a pure
regex approach... of course you may know that your text file
will not have any of those problems.


Cheers,
Kelly Clowers


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 1840f6971002270952g530d0427kc5f29a648db14b85@mail. gmail.com">http://lists.debian.org/1840f6971002270952g530d0427kc5f29a648db14b85@mail. gmail.com
 
Old 02-27-2010, 05:05 PM
Jonesy
 
Default perl or bash question

On Sat, 27 Feb 2010 12:40:39 -0500, Alex Janssen wrote:
> Vadkan Jozsef wrote:
>> How can I do that in bash or perl, that I have a txt file, e.g.:
>>
>> $cat file.txt
>> Hi, this is the content of the txt file, that contains links like this:
>> http://www.somewhere.it/, and it could contain: http://somewhere.com,
>> etc..
>> This is the second line, that doesn't contains links..
>> ..
>> This is the XYZ line, that contains a link: http://www.somewhere.net
>> $
>>
>> ...ok.. so how could I make a regexp for this?
>>
>> Turning:
>>
>> http://website.org
>> http://www.website.org
>>
>> to this:
>>
>> <a href=http://website.org>http://website.org</a>
>> <a href=http://www.website.org>http://www.website.org</a>
>>
>> The solution would be:
>>
>> sed 'SOMEMAGIC' file.txt > file.html
>> or
>> perl 'SOMEBIGMAGIC' file.txt > file.html
>>
> grep -io "<a.*</a>" somefile.html
> That'll extract just the href code.

... _IF_ it's all on one line -- which it usually ain't.

And, that's not what the OP wants.
He want's to href'ify URLs found in 'raw' text.

Jonesy
--
Marvin L Jones | jonz | W3DHJ | linux
38.24N 104.55W | @ config.com | Jonesy | OS/2
* Killfiling google & XXXXbanter.com: jonz.net/ng.htm


--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 02-27-2010, 05:15 PM
Alex Janssen
 
Default perl or bash question

Jonesy wrote:
> On Sat, 27 Feb 2010 12:40:39 -0500, Alex Janssen wrote:
>
>> Vadkan Jozsef wrote:
>>
>>> How can I do that in bash or perl, that I have a txt file, e.g.:
>>>
>>> $cat file.txt
>>> Hi, this is the content of the txt file, that contains links like this:
>>> http://www.somewhere.it/, and it could contain: http://somewhere.com,
>>> etc..
>>> This is the second line, that doesn't contains links..
>>> ..
>>> This is the XYZ line, that contains a link: http://www.somewhere.net
>>> $
>>>
>>> ...ok.. so how could I make a regexp for this?
>>>
>>> Turning:
>>>
>>> http://website.org
>>> http://www.website.org
>>>
>>> to this:
>>>
>>> <a href=http://website.org>http://website.org</a>
>>> <a href=http://www.website.org>http://www.website.org</a>
>>>
>>> The solution would be:
>>>
>>> sed 'SOMEMAGIC' file.txt > file.html
>>> or
>>> perl 'SOMEBIGMAGIC' file.txt > file.html
>>>
>>>
>> grep -io "<a.*</a>" somefile.html
>> That'll extract just the href code.
>>
>
> ... _IF_ it's all on one line -- which it usually ain't.
>
> And, that's not what the OP wants.
> He want's to href'ify URLs found in 'raw' text.
>
> Jonesy
>
Well, dang if you're not right. I retract my post. Oops! I'll have to
re-think that.

Alex

--
Ourwoods.org
Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. - Albert Einstein (275)


--
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 07:31 PM.

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