Ahora, si quieres un poco elegante expresión regular de la vieja escuela:
echo "foo.bar.tar.gz" | sed "s/^\(.*\)\..*$/\1/"
-> se convertirán: foo.bar.tar
I will break it down:
s/ Substitute
^ From the beginning
\( Mark
.* Everything (greedy way)
\) Stop Marking (the string marked goes to buffer 1)
\. until a "." (which will be the last dot, because of the greedy selection)
.* select everything (this is the extension that will be discarded)
$ until the end
/ With (substitute)
\1 The buffer 1 marked above (which is the filename before the last dot(.)
/ End
Cristiano Savino
que pueden fallar para una archivo llamado, por ejemplo, 'foo.bar.baz' si desea que el resultado sea' foo.bar'. –
Esto fue bastante bueno para mí, ya que quería que el nombre del archivo sea 'foo' desafortunadamente cuando el directorio también tiene un punto y falla. –