Hallo Marco, hallo LUG OWL. On Thu, Aug 06, 2009 at 12:59:42PM +0200, Marco Wiese wrote: > > Ich habe einen String im Format String1/String2/String3 > > Nun brauche ich davon aber immer nur den String nach dem letzten "/". > Die Länge ist allerdings variabel, so dass ich nciht weiß, wieviel > Slashes enthalten sind. Weiß jemand Rat, wie ich an den letzten > Schtring komme???
quick 'n dirty: s="foo/bar/foobar/a bc/wwe/asd/xy z" ; y=""; i=0; go=y; while [[ $go -eq y ]]; do i=$(( $i + 1 )) ; x=`echo $s | cut -d\/ -f $i`; echo $i x=$x ; if [[ $x = "" ]] ; then go=n && break ; fi; done; i=$(( $i-1 )); echo; x=`echo $s | cut -d\/ -f $i`; echo result: $x Idee: durchzählen, bis nix mehr kommt, dann den letzten davor ausgeben. Gruss Frank -- Linux mailing list [email protected] subscribe/unsubscribe: http://lug-owl.de/mailman/listinfo/linux Hinweise zur Nutzung: http://www.lug-owl.de/Mailingliste/hints.epo
