Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
sed-Wissen aus der Praxis für Noobs und Geeks
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

Goto page 1, 2, 3, 4, 5, 6, 7  Next  
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) Diskussionsforum
View previous topic :: View next topic  
Author Message
qp
n00b
n00b


Joined: 03 Jul 2007
Posts: 6

PostPosted: Tue Jul 03, 2007 6:58 pm    Post subject: sed-Wissen aus der Praxis für Noobs und Geeks Reply with quote

*edit* div. Threads zusammengeführt und Titel verallgemeinert --think4urs11

data.txt :
1 kirk
2 worf
3 spock
4 data
5 odo
6 kira
7 enterprise
8 chekov
9 riker
10 sulu
------ EOF----------

SED -n -e '/o/, /a/p' data.txt

Eigentlich sollte es von der 1.Zeile mit 'o' bis 1.Zeile mit 'a' ausgeben.
Also :
2 worf
3 spock
4 data

Aber die Ausgabe ist :
2 worf
3 spock
4 data
5 odo
6 kira
8 chekov
9 riker
10 sulu

Wieso? :?
Danke im voraus!!!
Back to top
View user's profile Send private message
think4urs11
Bodhisattva
Bodhisattva


Joined: 25 Jun 2003
Posts: 6659
Location: above the cloud

PostPosted: Tue Jul 03, 2007 7:02 pm    Post subject: Reply with quote

deutsch nur in den deutschen Foren, daher 'moved from Portage & Programming to Diskussionsforum'
_________________
Nothing is secure / Security is always a trade-off with usability / Do not assume anything / Trust no-one, nothing / Paranoia is your friend / Think for yourself
Back to top
View user's profile Send private message
Fauli
l33t
l33t


Joined: 24 Apr 2004
Posts: 760
Location: Moers, Germany

PostPosted: Tue Jul 03, 2007 7:28 pm    Post subject: Re: SED -n -e '/o/,/a/p' data.txt Reply with quote

qp wrote:
SED -n -e '/o/, /a/p' data.txt

Wenn sed das a gefunden hat, fängt es wieder von Neuem an, nach dem o zu suchen.
_________________
Do your part to beautify the web! Turn off link underlining!
Back to top
View user's profile Send private message
qp
n00b
n00b


Joined: 03 Jul 2007
Posts: 6

PostPosted: Tue Jul 03, 2007 9:05 pm    Post subject: Reply with quote

Ok, ich hab es schon geahnt... danke für die Antwort...
Und wie kann ich das unterdrücken, nämlich, dass SED genau
das erste Auftreten dieses Bereiches ausgibt? Ich hab probiert mit 'q', aber
klappt nicht so richtig...
Back to top
View user's profile Send private message
think4urs11
Bodhisattva
Bodhisattva


Joined: 25 Jun 2003
Posts: 6659
Location: above the cloud

PostPosted: Tue Jul 03, 2007 10:42 pm    Post subject: Reply with quote

Code:
 sed '/o/!d;:loop;N;/a/!b loop;q' data.txt

_________________
Nothing is secure / Security is always a trade-off with usability / Do not assume anything / Trust no-one, nothing / Paranoia is your friend / Think for yourself
Back to top
View user's profile Send private message
qp
n00b
n00b


Joined: 03 Jul 2007
Posts: 6

PostPosted: Wed Jul 04, 2007 10:10 pm    Post subject: sed -n "/^[^oe]*$/p" d2 Reply with quote

sed -n "/^[^oe]*$/p" data.txt
was macht diese Zeile genau??

/^[^oe]*/ bedeutet : es sollen keine e oder o (in beliebiger Menge) am Anfang der Zeile
stehen...

/^[^oe]*$/ heisst es nun, dass alles sich auf die letzte Zeile beziehen muss?
irgendwie verstehe ich es nicht..
Hat jemand eine Idee?

Danke im voraus!
Back to top
View user's profile Send private message
think4urs11
Bodhisattva
Bodhisattva


Joined: 25 Jun 2003
Posts: 6659
Location: above the cloud

PostPosted: Wed Jul 04, 2007 10:25 pm    Post subject: Reply with quote

im Zweifelsfall hilft einfach ausprobieren ;)

Dein Kommando gibt nur noch Zeilen aus in denen weder ein o noch ein e vorkommen.
_________________
Nothing is secure / Security is always a trade-off with usability / Do not assume anything / Trust no-one, nothing / Paranoia is your friend / Think for yourself
Back to top
View user's profile Send private message
qp
n00b
n00b


Joined: 03 Jul 2007
Posts: 6

PostPosted: Wed Jul 04, 2007 10:39 pm    Post subject: Reply with quote

ja klar, das kann man durch ausprobieren finden...
aber ich will die logik verstehen, die dahinter steht...
irgendwie ist es unlogisch - wozu sind erstes ^ und $ am Ende?
das ganze verwirrt sehr stark.. 8O
Back to top
View user's profile Send private message
think4urs11
Bodhisattva
Bodhisattva


Joined: 25 Jun 2003
Posts: 6659
Location: above the cloud

PostPosted: Wed Jul 04, 2007 10:59 pm    Post subject: Reply with quote

dir ist aber schon bewußt das hier das Gentooforum ist und nicht das fuer anonyme sed-geeks (wie mich)? ;)
...mein ja nur da deine Posts im Forum der letzten beiden Tage bisher außer sed eigentlich nur sed und gelegentlich sed zum Thema hatten...

lies dich mal durch ein paar howtos, z.B.
http://sed.sourceforge.net/ oder http://www-128.ibm.com/developerworks/linux/library/l-sed1.html
_________________
Nothing is secure / Security is always a trade-off with usability / Do not assume anything / Trust no-one, nothing / Paranoia is your friend / Think for yourself
Back to top
View user's profile Send private message
qp
n00b
n00b


Joined: 03 Jul 2007
Posts: 6

PostPosted: Wed Jul 04, 2007 11:08 pm    Post subject: Reply with quote

@Think4UrS11
Danke für den Hinweis! ;)
Ich bin extra auf Gentoo-Forum gekommen, weil ich aus meiner Erfahrung eindeutig
sagen kann : Unter Gentoo-People gibt's am meisten Hacker. Also wenn nicht
Gentoo-Forum, dann wer? :O
Back to top
View user's profile Send private message
think4urs11
Bodhisattva
Bodhisattva


Joined: 25 Jun 2003
Posts: 6659
Location: above the cloud

PostPosted: Wed Jul 04, 2007 11:10 pm    Post subject: Reply with quote

qp wrote:
Also wenn nicht Gentoo-Forum, dann wer? :O

Ok, DAS Argument lasse ich gelten :)
_________________
Nothing is secure / Security is always a trade-off with usability / Do not assume anything / Trust no-one, nothing / Paranoia is your friend / Think for yourself
Back to top
View user's profile Send private message
Ampheus
l33t
l33t


Joined: 19 Oct 2005
Posts: 814
Location: Rheine, NRW, Germany

PostPosted: Thu Jul 05, 2007 11:44 am    Post subject: Reply with quote

Danke für den Link.
Will mich endlich mal richtig mit sed befassen :)

Achja, das Lob von qp nehme ich natürlich auch gerne an :D
Back to top
View user's profile Send private message
nikaya
Veteran
Veteran


Joined: 13 May 2006
Posts: 1471
Location: Germany

PostPosted: Thu Jul 05, 2007 12:12 pm    Post subject: Reply with quote

Das Sed by example ist übrigens von drobbins. :wink:
_________________
Notes on Dhamma
How to waste your time: look for an explanation of consciousness, ask to know what feeling is. (Nanavira Thera)
Back to top
View user's profile Send private message
think4urs11
Bodhisattva
Bodhisattva


Joined: 25 Jun 2003
Posts: 6659
Location: above the cloud

PostPosted: Thu Jul 05, 2007 6:42 pm    Post subject: Reply with quote

Ampheus wrote:
Will mich endlich mal richtig mit sed befassen

Sehr löblich, sed ist was sehr feines; kommt selten vor das es mit sed nun wirklich nicht mehr geht.
Abschreckende Beispiele gefällig? 1, 2 8)

Ampheus wrote:
Danke für den Link.
john.doe wrote:
Das Sed by example ist übrigens von drobbins.

Eine leicht variierte Fassung der IBM-Artikel zu sed gibt es auch auf der Gentoo-HP bei den Dokumentationen; Abschnitt DeveloperWorks-Artikel, neben feinen Sachen zu awk, ssh key-Mgmt. und haste-nich-gesehen...

noch ein anderes howto: http://www.linux-fuer-alle.de/doc_show.php?docid=181&catid=8
_________________
Nothing is secure / Security is always a trade-off with usability / Do not assume anything / Trust no-one, nothing / Paranoia is your friend / Think for yourself
Back to top
View user's profile Send private message
Ampheus
l33t
l33t


Joined: 19 Oct 2005
Posts: 814
Location: Rheine, NRW, Germany

PostPosted: Thu Jul 05, 2007 7:39 pm    Post subject: Reply with quote

Meine Güte, wie lange arbeitest du schon mit sed?
Das Programm ist ja dermaßen mächtig...

Leider wirkt das auf mich immer sehr kryptisch :)

Naja da muss ich durch....
Back to top
View user's profile Send private message
Fauli
l33t
l33t


Joined: 24 Apr 2004
Posts: 760
Location: Moers, Germany

PostPosted: Thu Jul 05, 2007 8:58 pm    Post subject: Reply with quote

Ich weiß nicht, ob diese Skript-Sammlung schon in einer der oben verlinkten Seiten erwähnt wird, aber dort gibt's auch jede Menge Skripts von "basic" bis "extreme", inkl. Sokoban-Spiel.
_________________
Do your part to beautify the web! Turn off link underlining!
Back to top
View user's profile Send private message
sirro
Veteran
Veteran


Joined: 20 Jul 2003
Posts: 1472
Location: aachen.nrw.de.eu

PostPosted: Sat Jul 07, 2007 8:53 am    Post subject: Reply with quote

Hier ist ja mindestens ein sed-experte anwesend, darum stelle ich auch mal eine Frage:

Code:
#echo 'yyy zzz yyy' | sed -re 's#.*(zzz)?.*#xxx \1 xxx#;'
xxx  xxx

Wie bekomme ich es hin, dass er den optionalen Teil der RE mit ersetzt?

Also ein $BLACKMAGIC, so dass folgendes gilt:
Code:
#echo 'yyy zzz yyy' | sed -re $BLACKMAGIC
xxx zzz xxx
Back to top
View user's profile Send private message
think4urs11
Bodhisattva
Bodhisattva


Joined: 25 Jun 2003
Posts: 6659
Location: above the cloud

PostPosted: Sat Jul 07, 2007 9:04 am    Post subject: Reply with quote

meinst du das?
Code:
$ echo "yyy zzz yyy" | sed 's/yyy/xxx/g'
xxx zzz xxx

_________________
Nothing is secure / Security is always a trade-off with usability / Do not assume anything / Trust no-one, nothing / Paranoia is your friend / Think for yourself
Back to top
View user's profile Send private message
sirro
Veteran
Veteran


Joined: 20 Jul 2003
Posts: 1472
Location: aachen.nrw.de.eu

PostPosted: Sat Jul 07, 2007 9:13 am    Post subject: Reply with quote

Ne. Das Beispiel ist natuerlich vereinfacht.

Beispiel: Ich will aus einem User-Agent mehrere Angaben rausziehen, die aber variieren koennen.
Code:
SonyEricssonK750i/R1L Browser/SEMC-Browser/4Profile/MIDP-2.0 Configuration/CLDC-1.1
SonyEricssonM600i/R100 Mozilla/4.0 (compatible; MSIE 6.0; Symbian OS; 513) Opera 8.65 [en]

"SonyEricsson" ist bei allen gleich, darauf folgt das Modell. Soweit so einfach.
Allerdings hat nicht jedes Modell auch Symbian und Opera. Also will ich eine RE, die mir den Agent durch den Modell-Namen ersetzt und falls vorhanden auch noch die Angaben, dass es ein Symbian ist oder einen Opera-Browser benutzt.

Mit mehreren Ausdruecken (fuer jeden moeglichen Fall eine) ist das natuerlich kein Problem, aber das ist ja die unelegante Methode. :)


Ergebnis soll also etwas aehnliches sein wie:
Code:
M600i (Symbian OS; Opera 8.65)
SonyEricssonK750i ()
Back to top
View user's profile Send private message
Ampheus
l33t
l33t


Joined: 19 Oct 2005
Posts: 814
Location: Rheine, NRW, Germany

PostPosted: Sat Jul 07, 2007 9:32 am    Post subject: Reply with quote

hehe dann möchte ich auch nochmal :)

Code:
sed -e 's/<? /<?php /' -e 's/<?[^php]/<?php /' test.txt | less

test.txt:
Code:
<?foo
<? foo
<?php foo

Leider funktioniert es nicht ganz, da bei der ersten Zeile zwar der String richtig ersetzt wird, aber der darauffolgende um 1 Zeichen gekürzt wird.
Also so siehts dann aus:
Code:
<?php oo
<?php foo
<?php foo
Back to top
View user's profile Send private message
sirro
Veteran
Veteran


Joined: 20 Jul 2003
Posts: 1472
Location: aachen.nrw.de.eu

PostPosted: Sat Jul 07, 2007 9:40 am    Post subject: Reply with quote

Ampheus wrote:
s/<?[^php]/<?php /'

Das funktioniert so nicht. ™

Das fette sagt, dass auf "<?" EIN zeichen folgt, dass weder 'p' noch 'h' ist. Da trifft auf deine erste Zeile zu, da 'f' weder 'p' noch 'h' ist also wird es mit <?php ersetzt.

Was du wahrscheinlich willst ist, dass der ganze ausdruck !="php" gematcht wird. Bisher habe ich da noch keine andere Loesung gesehen als die Zeichen aufwaendig einzeln in der Reihenfolge zu matchen und dann spaeter mit \1 wieder einsetzen: [^p][^h][^p]. Bei 3 Buchstaben ist das zwar nicht mehr uebersichtlich aber der overhead haelt sich in grenzen.

Evtl. geht es aber auch noch anders ;-)

Code:
sed -e 's/<? /<?php /' -e 's/<?\([^p][^h][^p]\)/<?php \1/' test.txt
Back to top
View user's profile Send private message
Ampheus
l33t
l33t


Joined: 19 Oct 2005
Posts: 814
Location: Rheine, NRW, Germany

PostPosted: Sat Jul 07, 2007 10:34 am    Post subject: Reply with quote

Ah danke, die \1 hat mir geholfen :)
Back to top
View user's profile Send private message
think4urs11
Bodhisattva
Bodhisattva


Joined: 25 Jun 2003
Posts: 6659
Location: above the cloud

PostPosted: Sat Jul 07, 2007 6:23 pm    Post subject: Reply with quote

@sirro:
'n quickhack; weder elegant noch schön aber funktioniert :roll:
Code:
sed 'G;s/ /\n/g' agent.log | sed '/Symbian/{N;s/\n/ /;b};/Opera/{N;s/\n/ /;b}' | sed '/Sony\|Symbian\|Opera/b;d' | sed 's/^SonyEricsson\(.*\)$/\n\1/' | sed '/^$/b;:x;$!N;s/\n\(.\)/ \1/;t x'

_________________
Nothing is secure / Security is always a trade-off with usability / Do not assume anything / Trust no-one, nothing / Paranoia is your friend / Think for yourself


Last edited by think4urs11 on Sun Jul 08, 2007 2:23 pm; edited 2 times in total
Back to top
View user's profile Send private message
sirro
Veteran
Veteran


Joined: 20 Jul 2003
Posts: 1472
Location: aachen.nrw.de.eu

PostPosted: Sun Jul 08, 2007 2:19 pm    Post subject: Reply with quote

Immerhin :-)

Aber da das in einer einzigen langen sed-Datei ist komme ich mit einem grep zwischendurch auch nicht weiter.
Hab jetzt einfach zwei Zeilen draus gemacht und nur nach Opera abgefragt, das muss reichen.
Back to top
View user's profile Send private message
think4urs11
Bodhisattva
Bodhisattva


Joined: 25 Jun 2003
Posts: 6659
Location: above the cloud

PostPosted: Sun Jul 08, 2007 2:23 pm    Post subject: Reply with quote

geht auch ganz ohne grep - hab es oben korrigiert ;)
_________________
Nothing is secure / Security is always a trade-off with usability / Do not assume anything / Trust no-one, nothing / Paranoia is your friend / Think for yourself
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
Goto page 1, 2, 3, 4, 5, 6, 7  Next
Page 1 of 7

 
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