[b][red]This message was edited by abc at 2002-10-16 18:58:16[/red][/b][hr] echo "filename.java" | sed -n 's/(.*).[^.]*$/1/p'
the replace command cuts the last dot and all that comes after it
[blue]correction[/blue] - the previous version does not display files that have no extension (like "filename"). To do that use:
echo "filename.java" | sed -n 's/(.*).[^.]*$|$/1/p'
translated, sed searches ('s/') for the pattern '(.*).[^.]*$|$' - meaning 'any letter' (.) 'zero or more times' (*) followed by either a dot ('.'), then any non-dot letter ('[^,]) zero or more times and end of line ('$') or directly the end of line; then replaces this pattern with 1, which is the text matching the pattern between the first ( and ) pair.
Comments
echo "filename.java" | sed -n 's/(.*).[^.]*$/1/p'
the replace command cuts the last dot and all that comes after it
[blue]correction[/blue] - the previous version does not display files that have no extension (like "filename"). To do that use:
echo "filename.java" | sed -n 's/(.*).[^.]*$|$/1/p'
translated, sed searches ('s/') for the pattern '(.*).[^.]*$|$' - meaning 'any letter' (.) 'zero or more times' (*) followed by either a dot ('.'), then any non-dot letter ('[^,]) zero or more times and end of line ('$') or directly the end of line; then replaces this pattern with 1, which is the text matching the pattern between the first ( and ) pair.