View previous topic :: View next topic |
Author |
Message |
Mac Fly Guru
![Guru Guru](/images/ranks/rank_rect_3.gif)
Joined: 30 Nov 2003 Posts: 330 Location: nähe Stuttgart
|
Posted: Wed Jun 23, 2004 11:05 pm Post subject: [OT] sed-Frage |
|
|
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:
Und ans Ende soll eben nochmal die Addy dranstehen und
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 |
|
![](templates/gentoo/images/spacer.gif) |
kiezpro Tux's lil' helper
![Tux's lil' helper Tux's lil' helper](/images/ranks/rank_rect_1.gif)
![](images/avatars/119194096340e12f8940e24.gif)
Joined: 13 May 2004 Posts: 126 Location: Yes
|
Posted: Wed Jun 23, 2004 11:26 pm Post subject: |
|
|
Moin,
das hier sollte gehen:
Code: | cat new.txt | sed -e 's/^\(.*\)$/<a href="\1">\1<\/a>/' > new.html |
|
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
Mac Fly Guru
![Guru Guru](/images/ranks/rank_rect_3.gif)
Joined: 30 Nov 2003 Posts: 330 Location: nähe Stuttgart
|
Posted: Wed Jun 23, 2004 11:44 pm Post subject: |
|
|
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 |
|
![](templates/gentoo/images/spacer.gif) |
kiezpro Tux's lil' helper
![Tux's lil' helper Tux's lil' helper](/images/ranks/rank_rect_1.gif)
![](images/avatars/119194096340e12f8940e24.gif)
Joined: 13 May 2004 Posts: 126 Location: Yes
|
Posted: Thu Jun 24, 2004 3:15 am Post subject: |
|
|
Dann wohl eher so?
Code: | cat new.txt | sed -e 's/^\(.*\)[\r\n]$/<a href="\1">\1<\/a><br>/' > new.html |
|
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
toskala Advocate
![Advocate Advocate](/images/ranks/rank-G-1-advocate.gif)
![](images/avatars/15247838633ff9618bdf5b6.gif)
Joined: 14 Dec 2002 Posts: 2080 Location: hamburg, germany
|
Posted: Thu Jun 24, 2004 10:45 am Post subject: |
|
|
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 |
|
![](templates/gentoo/images/spacer.gif) |
Earthwings Bodhisattva
![Bodhisattva Bodhisattva](/images/ranks/rank-bodhisattva.gif)
![](images/avatars/49753421747790001d409d.png)
Joined: 14 Apr 2003 Posts: 7753 Location: Germany
|
Posted: Thu Jun 24, 2004 12:51 pm Post subject: |
|
|
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 |
|
![](templates/gentoo/images/spacer.gif) |
toskala Advocate
![Advocate Advocate](/images/ranks/rank-G-1-advocate.gif)
![](images/avatars/15247838633ff9618bdf5b6.gif)
Joined: 14 Dec 2002 Posts: 2080 Location: hamburg, germany
|
Posted: Thu Jun 24, 2004 12:54 pm Post subject: |
|
|
harhar, ja, der ist auch gut
aber welcher wohl performanter ist *duck* ![Smile :)](images/smiles/icon_smile.gif) _________________ adopt an unanswered post
erst denken, dann posten |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
Earthwings Bodhisattva
![Bodhisattva Bodhisattva](/images/ranks/rank-bodhisattva.gif)
![](images/avatars/49753421747790001d409d.png)
Joined: 14 Apr 2003 Posts: 7753 Location: Germany
|
Posted: Thu Jun 24, 2004 12:57 pm Post subject: |
|
|
Du willst jawohl nicht behaupten, das sed mit regexps und Verwendung von backmatching schneller als die bash ist ![Smile :)](images/smiles/icon_smile.gif) |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
toskala Advocate
![Advocate Advocate](/images/ranks/rank-G-1-advocate.gif)
![](images/avatars/15247838633ff9618bdf5b6.gif)
Joined: 14 Dec 2002 Posts: 2080 Location: hamburg, germany
|
Posted: Thu Jun 24, 2004 1:32 pm Post subject: |
|
|
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 ![Cool 8)](images/smiles/icon_cool.gif) _________________ adopt an unanswered post
erst denken, dann posten |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
toskala Advocate
![Advocate Advocate](/images/ranks/rank-G-1-advocate.gif)
![](images/avatars/15247838633ff9618bdf5b6.gif)
Joined: 14 Dec 2002 Posts: 2080 Location: hamburg, germany
|
Posted: Thu Jun 24, 2004 1:46 pm Post subject: |
|
|
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 ![Smile :)](images/smiles/icon_smile.gif) _________________ adopt an unanswered post
erst denken, dann posten |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
Earthwings Bodhisattva
![Bodhisattva Bodhisattva](/images/ranks/rank-bodhisattva.gif)
![](images/avatars/49753421747790001d409d.png)
Joined: 14 Apr 2003 Posts: 7753 Location: Germany
|
Posted: Thu Jun 24, 2004 2:07 pm Post subject: |
|
|
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 |
|
![](templates/gentoo/images/spacer.gif) |
toskala Advocate
![Advocate Advocate](/images/ranks/rank-G-1-advocate.gif)
![](images/avatars/15247838633ff9618bdf5b6.gif)
Joined: 14 Dec 2002 Posts: 2080 Location: hamburg, germany
|
Posted: Thu Jun 24, 2004 2:08 pm Post subject: |
|
|
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 ![Smile :-)](images/smiles/icon_smile.gif) _________________ adopt an unanswered post
erst denken, dann posten |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
toskala Advocate
![Advocate Advocate](/images/ranks/rank-G-1-advocate.gif)
![](images/avatars/15247838633ff9618bdf5b6.gif)
Joined: 14 Dec 2002 Posts: 2080 Location: hamburg, germany
|
Posted: Thu Jun 24, 2004 2:28 pm Post subject: |
|
|
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 |
|
![](templates/gentoo/images/spacer.gif) |
Earthwings Bodhisattva
![Bodhisattva Bodhisattva](/images/ranks/rank-bodhisattva.gif)
![](images/avatars/49753421747790001d409d.png)
Joined: 14 Apr 2003 Posts: 7753 Location: Germany
|
Posted: Thu Jun 24, 2004 4:00 pm Post subject: |
|
|
Wundert mich, da es bei mir mit 350.000 zeilen fast ne Minute gebraucht hat. |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
Deever Veteran
![Veteran Veteran](/images/ranks/rank_rect_5_vet.gif)
![](images/avatars/d9a2e9133d29eda9e7305.gif)
Joined: 06 Jul 2002 Posts: 1354 Location: Zürich / Switzerland
|
Posted: Thu Jun 24, 2004 4:13 pm Post subject: |
|
|
Wozu sed, wenn es den 'awk' gibt?
Code: | ... | awk '/^http/ {printf('<a href="%s">%s</a><br/>', $0,$0);}' | ... |
HTH!
/dev |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
toskala Advocate
![Advocate Advocate](/images/ranks/rank-G-1-advocate.gif)
![](images/avatars/15247838633ff9618bdf5b6.gif)
Joined: 14 Dec 2002 Posts: 2080 Location: hamburg, germany
|
Posted: Thu Jun 24, 2004 4:56 pm Post subject: |
|
|
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 |
|
![](templates/gentoo/images/spacer.gif) |
Mac Fly Guru
![Guru Guru](/images/ranks/rank_rect_3.gif)
Joined: 30 Nov 2003 Posts: 330 Location: nähe Stuttgart
|
Posted: Fri Jun 25, 2004 3:42 pm Post subject: |
|
|
Hui, ganz schön viel Interesse an dem Thread. Nochmals vielen Dank, hat super funktioniert ![Smile :)](images/smiles/icon_smile.gif) |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
kiezpro Tux's lil' helper
![Tux's lil' helper Tux's lil' helper](/images/ranks/rank_rect_1.gif)
![](images/avatars/119194096340e12f8940e24.gif)
Joined: 13 May 2004 Posts: 126 Location: Yes
|
Posted: Fri Jun 25, 2004 9:29 pm Post subject: |
|
|
IMHO: hier waren einige Leute, die sich sehr gelangweilt haben... aber wenn's funktioniert hat, ist der Zweck ja erfüllt. |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
|