OT: Shell script
Björn König
bkoenig at cs.tu-berlin.de
Mon Jul 11 19:35:00 GMT 2005
Brian Henning wrote:
> I am trying to write an SH script that i need some functionality.
>
> I want it to be able to get a filename without the extention on the end.
>
> for example.
>
> file.mp3
>
> i would like it to return 'file'.
>
> Any ideas?
This one looks ugly, but works fine:
echo 'this.is.a.filename.with.extension' | awk -F. '{ i = 2; s = $1 } {
while ( i < NF ) { s = s "." $i ;i += 1; } } { print s }'
Don't hesitate to use awk. Although it looks more complex it's often
"faster" than any equivalent solution with sed.
Björn
More information about the freebsd-questions
mailing list