Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[OT] sed-Frage
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) Diskussionsforum
View previous topic :: View next topic  
Author Message
Mac Fly
Guru
Guru


Joined: 30 Nov 2003
Posts: 330
Location: nähe Stuttgart

PostPosted: Wed Jun 23, 2004 11:05 pm    Post subject: [OT] sed-Frage Reply with quote

Ich hab ein txt-file mit lauter http-Adressen mit User/pass
Code:
http://0037:pb351@www.xxx.com/members/


Nun möchte ich dies in ein html file umwandeln. Also soll an den Anfang:
Code:
<a href="


Und ans Ende soll eben nochmal die Addy dranstehen und
Code:
</a>


So das am ende dies herauskommt:
Code:
<a href=\"http://0037:pb351@www.xxx.com/members/">0037:pb351@www.xxx.com/members/</a>


Bis jetzt hab ichs so, aber das funktioniert nicht so, wie ich das will:
Code:
sed -e '/http*/c\<a href=\"http' new.txt > new.html


Wie fange ich das an? Oder kennt jemand ein gutes Sed-Howto?

mod edit: [OT] gesetzt. amne


Last edited by Mac Fly on Wed Jun 23, 2004 11:36 pm; edited 1 time in total
Back to top
View user's profile Send private message
kiezpro
Tux's lil' helper
Tux's lil' helper


Joined: 13 May 2004
Posts: 126
Location: Yes

PostPosted: Wed Jun 23, 2004 11:26 pm    Post subject: Reply with quote

Moin,
das hier sollte gehen:

Code:
cat new.txt | sed -e 's/^\(.*\)$/<a href="\1">\1<\/a>/' > new.html
Back to top
View user's profile Send private message
Mac Fly
Guru
Guru


Joined: 30 Nov 2003
Posts: 330
Location: nähe Stuttgart

PostPosted: Wed Jun 23, 2004 11:44 pm    Post subject: Reply with quote

Besten Dank für die schnelle Antwort :)
Ich hab aber vergessen, das ein <br> noch dran soll. Also hab ich es editiert.
Code:
cat new.txt | sed -e 's/^\(.*\)$/<a href="\1">\1<\/a><br>/' > new.html

Aber da sind zwei Zeilenumbrüche zu viel drin.

Code:
<a href="http://user:pass@domain.com/axs//
">http://user:pass@xxx.com/axs//
</a><br>


Es funktioniert zwar, aber wie beheb ich das?
Back to top
View user's profile Send private message
kiezpro
Tux's lil' helper
Tux's lil' helper


Joined: 13 May 2004
Posts: 126
Location: Yes

PostPosted: Thu Jun 24, 2004 3:15 am    Post subject: Reply with quote

Dann wohl eher so?

Code:
cat new.txt | sed -e 's/^\(.*\)[\r\n]$/<a href="\1">\1<\/a><br>/' > new.html
Back to top
View user's profile Send private message
toskala
Advocate
Advocate


Joined: 14 Dec 2002
Posts: 2080
Location: hamburg, germany

PostPosted: Thu Jun 24, 2004 10:45 am    Post subject: Reply with quote

das ist ja wieder cat abuse :)

wozu kann sed denn mit input files umgehen :)

edit: na net das es jetzt wieder heisst ich mecker nur:

Code:
sed -e 's/^\(.*\)$/<a href="\1">\1<\/a>/' foo > bar.html

_________________
adopt an unanswered post
erst denken, dann posten
Back to top
View user's profile Send private message
Earthwings
Bodhisattva
Bodhisattva


Joined: 14 Apr 2003
Posts: 7753
Location: Germany

PostPosted: Thu Jun 24, 2004 12:51 pm    Post subject: Reply with quote

Wohl eher sed abuse, oder warum reicht die bash nicht?
Code:

{ while read line; do echo "<a href=\\\"${line}\\\">${line}</a><br/>"; done } < new.txt > new.html
Back to top
View user's profile Send private message
toskala
Advocate
Advocate


Joined: 14 Dec 2002
Posts: 2080
Location: hamburg, germany

PostPosted: Thu Jun 24, 2004 12:54 pm    Post subject: Reply with quote

harhar, ja, der ist auch gut :D
aber welcher wohl performanter ist *duck* :)
_________________
adopt an unanswered post
erst denken, dann posten
Back to top
View user's profile Send private message
Earthwings
Bodhisattva
Bodhisattva


Joined: 14 Apr 2003
Posts: 7753
Location: Germany

PostPosted: Thu Jun 24, 2004 12:57 pm    Post subject: Reply with quote

Du willst jawohl nicht behaupten, das sed mit regexps und Verwendung von backmatching schneller als die bash ist :)
Back to top
View user's profile Send private message
toskala
Advocate
Advocate


Joined: 14 Dec 2002
Posts: 2080
Location: hamburg, germany

PostPosted: Thu Jun 24, 2004 1:32 pm    Post subject: Reply with quote

hmm, naja, wenn man den sed aufruft und ihn ein großes file intern parsen lässt dann ist ja nur noch der sed aktiv und er schreibt den output, ich bin mir gar nich so sicher, dass die bash mit der schleife schneller ist als der sed mit inputfile ohne cat.

aber ich glaub nicht, dass das noch wichtig ist für die pr0n link-liste 8)
_________________
adopt an unanswered post
erst denken, dann posten
Back to top
View user's profile Send private message
toskala
Advocate
Advocate


Joined: 14 Dec 2002
Posts: 2080
Location: hamburg, germany

PostPosted: Thu Jun 24, 2004 1:46 pm    Post subject: Reply with quote

hrhrhr, der nutzlose benchmark :)

Quote:

system:

model name : Intel(R) Xeon(TM) CPU 2.20GHz
stepping : 7
cpu MHz : 2192.971
cache size : 512 KB

1GB ram


Code:

das script soll eine liste erzeugen mit 100000 einträgen ;)

#!/bin/bash
COUNTER="0"
LIMIT="100000"
URL="http://0037:pb351@www.xxx.com/members/"
LIST="/tmp/foo/list"

while [ $COUNTER -lt $LIMIT ]
    do echo -e "$URL" >> $LIST
    COUNTER=$(($COUNTER+1))
done



Quote:

root@mail:/tmp/foo> sed -e 's/^\(.*\)$/<a href="\1">\1<\/a>/' list > urls.txt

real 0m3.445s
user 0m3.370s
sys 0m0.040s


root@mail:/tmp/foo> time { while read line; do echo "<a href=\\\"${line}\\\">${line}</a><br/>"; done } < list > urls.txt

real 0m5.360s
user 0m4.540s
sys 0m0.750s


HA! der sed ist schneller ;)

uups, da ist mir doch der fehlerteufel untergekommen *änder* der sed aufruf ist jetzt korrekt :)
_________________
adopt an unanswered post
erst denken, dann posten
Back to top
View user's profile Send private message
Earthwings
Bodhisattva
Bodhisattva


Joined: 14 Apr 2003
Posts: 7753
Location: Germany

PostPosted: Thu Jun 24, 2004 2:07 pm    Post subject: Reply with quote

Das ist ja auch ein Mogel-Benchmark. Wenn immer die gleiche Zeile drinsteht, muss sed die regexps nicht neu berechnen und ist schneller. Ich habs mit 350.000 Zeilen und nur fünf verschiedenen, sich abwechselnden URLS probiert, da braucht sed bereits doppelt so lange. Man könnte es mal mit zufälligen URLs in den Zeilen versuchen, da sähe es wohl noch schlechter aus.
Back to top
View user's profile Send private message
toskala
Advocate
Advocate


Joined: 14 Dec 2002
Posts: 2080
Location: hamburg, germany

PostPosted: Thu Jun 24, 2004 2:08 pm    Post subject: Reply with quote

ja, das hab ich mir auch gedacht, evtl. sollten die urls wirklich alle verschieden sein, ich muss da mal gleich dran rumdenken wenn die support-anrufe nachlassen ;)

hmm, okay ich glaub du hast gewonnen :-)
_________________
adopt an unanswered post
erst denken, dann posten
Back to top
View user's profile Send private message
toskala
Advocate
Advocate


Joined: 14 Dec 2002
Posts: 2080
Location: hamburg, germany

PostPosted: Thu Jun 24, 2004 2:28 pm    Post subject: Reply with quote

hmm, also selbst wenn ich den mogel benchmark nehme, und den tip eines guten bekannten beherzige, dann ist sed so dennoch sehr fix ;)

Code:
root@mail:/tmp/foo> time sed -e 's/.*/\<a href\="&"\>&\<\/a\>/' list > urls.txt

real    0m0.348s
user    0m0.330s
sys     0m0.020s

_________________
adopt an unanswered post
erst denken, dann posten
Back to top
View user's profile Send private message
Earthwings
Bodhisattva
Bodhisattva


Joined: 14 Apr 2003
Posts: 7753
Location: Germany

PostPosted: Thu Jun 24, 2004 4:00 pm    Post subject: Reply with quote

Wundert mich, da es bei mir mit 350.000 zeilen fast ne Minute gebraucht hat.
Back to top
View user's profile Send private message
Deever
Veteran
Veteran


Joined: 06 Jul 2002
Posts: 1354
Location: Zürich / Switzerland

PostPosted: Thu Jun 24, 2004 4:13 pm    Post subject: Reply with quote

Wozu sed, wenn es den 'awk' gibt? ;)
Code:
... | awk '/^http/ {printf('<a href="%s">%s</a><br/>', $0,$0);}' | ...


HTH!
/dev
Back to top
View user's profile Send private message
toskala
Advocate
Advocate


Joined: 14 Dec 2002
Posts: 2080
Location: hamburg, germany

PostPosted: Thu Jun 24, 2004 4:56 pm    Post subject: Reply with quote

Earthwings wrote:
Wundert mich, da es bei mir mit 350.000 zeilen fast ne Minute gebraucht hat.


naja, hier sollte es kein problem mehr sein, da keine automaten mehr gebildet werden müssen für den regex
_________________
adopt an unanswered post
erst denken, dann posten
Back to top
View user's profile Send private message
Mac Fly
Guru
Guru


Joined: 30 Nov 2003
Posts: 330
Location: nähe Stuttgart

PostPosted: Fri Jun 25, 2004 3:42 pm    Post subject: Reply with quote

Hui, ganz schön viel Interesse an dem Thread. Nochmals vielen Dank, hat super funktioniert :)
Back to top
View user's profile Send private message
kiezpro
Tux's lil' helper
Tux's lil' helper


Joined: 13 May 2004
Posts: 126
Location: Yes

PostPosted: Fri Jun 25, 2004 9:29 pm    Post subject: Reply with quote

IMHO: hier waren einige Leute, die sich sehr gelangweilt haben... aber wenn's funktioniert hat, ist der Zweck ja erfüllt.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) Diskussionsforum All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum