Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[solved] [OT] [sed] letztes "/" löschen
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
pablo_supertux
Advocate
Advocate


Joined: 25 Jan 2004
Posts: 2931
Location: Somewhere between reality and Middle-Earth and in Freiburg (Germany)

PostPosted: Tue Aug 16, 2005 3:58 pm    Post subject: [solved] [OT] [sed] letztes "/" löschen Reply with quote

Hi

ich versuche mit sed das letzte / eines Pfades zu löschen, aber irgendwie kriege ich das nicht so richtig hin. Wenn ich (z.b. von pwd)

Code:

pwd | sed -e 's/\///'


aber da wird nur das erste / gelöscht. Mit

Code:

pwd | sed -e 's/\///g'


werden alle gelöscht. Aber wie krige ich es hin, dass nur das letzte / gelöscht wird? Ich hab bisher so gemacht:

Code:

echo `pwd | sed -e 's/\//@@@/g;'`o | sed -e 's/@@@o//;s/@@@/\//g'


aber das ist ehrlich gesagt viel zu umständlich und das dummste daran ist, würde kein / am Ende stehen, dann stünde ein "o" hintendran und das soll auch nicht sein. Wie kann ich das am besten lösen?
_________________
A! Elbereth Gilthoniel!
silivren penna míriel
o menel aglar elenath,
Gilthoniel, A! Elbereth!


Last edited by pablo_supertux on Tue Aug 16, 2005 4:14 pm; edited 1 time in total
Back to top
View user's profile Send private message
Edorian
n00b
n00b


Joined: 14 May 2004
Posts: 34
Location: Aachen, Germany

PostPosted: Tue Aug 16, 2005 4:07 pm    Post subject: Reply with quote

Willst du bei einer Pfadangabe wie /foo/bar/ das letzte / löschen?

dann brauchst du nur ein $-Zeichen zu verwenden, daß das Ende der Zeile matcht
Code:
sed -e 's/\/$//'
Back to top
View user's profile Send private message
STiGMaTa_ch
Veteran
Veteran


Joined: 28 Dec 2004
Posts: 1686
Location: Rüti ZH / Schweiz

PostPosted: Tue Aug 16, 2005 4:11 pm    Post subject: Reply with quote

erm... kannst du mal ein Beispiel machen?

Denn wenn ich bei mir einen pwd mache, habe ich keinen / am Schluss. z.B.
Code:
# pwd
/usr/portage/packages


Oder willst du, dass dann z.B. /packages gelöscht wird?

also z.B.
Code:
# pwd
/usr/portage/packages

# pwd | <some_voodo>
/usr/portage


:?: :?:

Lieber Gruss
STiGMaTa
Back to top
View user's profile Send private message
pablo_supertux
Advocate
Advocate


Joined: 25 Jan 2004
Posts: 2931
Location: Somewhere between reality and Middle-Earth and in Freiburg (Germany)

PostPosted: Tue Aug 16, 2005 4:14 pm    Post subject: Reply with quote

Edorian wrote:
Willst du bei einer Pfadangabe wie /foo/bar/ das letzte / löschen?

dann brauchst du nur ein $-Zeichen zu verwenden, daß das Ende der Zeile matcht
Code:
sed -e 's/\/$//'


Genau das habe ich gesucht, danke schön.

@stigmata: nein, ich wollte zum Beispiel von /home/supertux/waswasich/ das letzt / (damit ich nur /home/supertux/waswasich) bekomme.
_________________
A! Elbereth Gilthoniel!
silivren penna míriel
o menel aglar elenath,
Gilthoniel, A! Elbereth!
Back to top
View user's profile Send private message
smg
Veteran
Veteran


Joined: 13 Aug 2004
Posts: 1402
Location: /home/stephan

PostPosted: Tue Aug 16, 2005 5:31 pm    Post subject: Reply with quote

pablo_supertux wrote:
Edorian wrote:
Willst du bei einer Pfadangabe wie /foo/bar/ das letzte / löschen?

dann brauchst du nur ein $-Zeichen zu verwenden, daß das Ende der Zeile matcht
Code:
sed -e 's/\/$//'


Genau das habe ich gesucht, danke schön.

@stigmata: nein, ich wollte zum Beispiel von /home/supertux/waswasich/ das letzt / (damit ich nur /home/supertux/waswasich) bekomme.


Whatever, bei einer normalen pwd ausgabe erscheint kein slash am Schluss...

cheers.
_________________
GnuPG-Key-ID: 0xF8C275D4
Fingerprint: 5B6F 134A 189B A24D 342B 0961 8D4B 0230 F8C2 75D4
Code:
perl -WTe '($")=$/;print qq(@{[reverse('0'..'100')]}$/BOOM!$/);'
Back to top
View user's profile Send private message
pablo_supertux
Advocate
Advocate


Joined: 25 Jan 2004
Posts: 2931
Location: Somewhere between reality and Middle-Earth and in Freiburg (Germany)

PostPosted: Tue Aug 16, 2005 5:50 pm    Post subject: Reply with quote

bei mir schon. Aber es kommt nicht auf pwd an, weil das nur ein Bsp. war.
_________________
A! Elbereth Gilthoniel!
silivren penna míriel
o menel aglar elenath,
Gilthoniel, A! Elbereth!
Back to top
View user's profile Send private message
smg
Veteran
Veteran


Joined: 13 Aug 2004
Posts: 1402
Location: /home/stephan

PostPosted: Tue Aug 16, 2005 6:17 pm    Post subject: Reply with quote

pablo_supertux wrote:
bei mir schon. Aber es kommt nicht auf pwd an, weil das nur ein Bsp. war.


Achso. :) Das ist was anderes, dachte schon dass da bei dir was anderes kaputt ist. *g

cheers.
_________________
GnuPG-Key-ID: 0xF8C275D4
Fingerprint: 5B6F 134A 189B A24D 342B 0961 8D4B 0230 F8C2 75D4
Code:
perl -WTe '($")=$/;print qq(@{[reverse('0'..'100')]}$/BOOM!$/);'
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