Hi,
Could somebody tell me how to, with a command, display a filename
without its extension? For example, for 'abc.txt', the command
displays 'abc'. Thanx.
David
Could somebody tell me how to, with a command, display a filename
without its extension? For example, for 'abc.txt', the command
displays 'abc'. Thanx.
David
There is no such command because UNIX doesn't has extensions. The '.'Quote:> Could somebody tell me how to, with a command, display a filename
> without its extension? For example, for 'abc.txt', the command
> displays 'abc'. Thanx.
${a%.*}
This also works for files like 'abc.def.ghi' where this cuts of just
the 'last extension', giving 'abc.def'.
Regards, Jens
--
_ _____ _____
_ | | | | | | AG Moebius, Institut fuer Molekuelphysik
| |_| | | | | | Fachbereich Physik, Freie Universitaet Berlin
\___/ens|_|homs|_|oerring Tel: ++49 (0)30 838 - 53394 / FAX: - 56046
echo abc.c | cut -d. -f1 will print 'abc'
--Quote:> Hi,
> Could somebody tell me how to, with a command, display a filename
> without its extension? For example, for 'abc.txt', the command
> displays 'abc'. Thanx.
> David
> There is no such command because UNIX doesn't has extensions. The '.'
> is just another character you can have in your filename and it isn't
> special in any respect. This said, of course you can get rid of every-
> thing including and following a point. Since you don't specify in
> what context you want to do this I can just guess and give you an
> example in bash: If your filename, say 'abc.def', is stored in the
> variable a you get the filename without the 'extension' by using
Lee> Hi, Could somebody tell me how to, with a command, display a filename
Lee> without its extension? For example, for 'abc.txt', the command displays
Lee> 'abc'. Thanx.
Command basename(1) is closest. Actually, basename is used in removing
directory part of the filename, like
$ basename /d1/d2.ext2/d3/d4.ext4/file.ext5
file.ext5
If you give extension, you get
$ basename /d1/d2.ext2/d3/d4.ext4/file.ext5 .ext5
file
But, you have to know the extension already.
--
University of Tampere, Department of Computer and Information Sciences
Tampere, Finland http://www.cs.uta.fi/~av/
>> There is no such command because UNIX doesn't has extensions. The '.'
>> is just another character you can have in your filename and it isn't
>> special in any respect. This said, of course you can get rid of every-
>> thing including and following a point. Since you don't specify in
>> what context you want to do this I can just guess and give you an
>> example in bash: If your filename, say 'abc.def', is stored in the
>> variable a you get the filename without the 'extension' by using
>UNIX doesn't use extensions to determine executables, but it most certainly
>does use extensions. The command to see a filename without the extension is
>'dirname'. To see _just_ the filename, without extension or path, is
>'basename'.
% dirname /tmp/foo.txt
/tmp
% basename /tmp/foo.txt
foo.txt
--
-- Steve __
D'oh! I should have read on and I would have learned about the
'suffix' arg to basename before posting.
% basename /tmp/foo.txt .txt
foo
That's a new one for me.
--
-- Steve __
Use 'basename'.
It has a lot of options, or write some command yourself. That must not
be too difficult, I suppose.
Quote:>Hi,
>Could somebody tell me how to, with a command, display a filename
>without its extension? For example, for 'abc.txt', the command
>displays 'abc'. Thanx.
>David
If you know what the extension is, you can simpy type:Quote:>Hi,
>Could somebody tell me how to, with a command, display a filename
>without its extension? For example, for 'abc.txt', the command
>displays 'abc'. Thanx.
>David
basename foo.bar .bar
--
Project : http://freshmeat.net/projects/vsh
> You could try cut as well,
> echo abc.c | cut -d. -f1 will print 'abc'
Juergen
1. URLs Without Filename Extensions?
I've noticed that on a few sites (e.g., W3C and ApacheWeek) that many of
the URLs don't have the expected (at least by me ;-) .html, .htm, .gif, ...
filename extensions.
I assume, given the frequency of occurence on these sites, that this is by
design? If so, what is the rationale, and is this a "good thing" (i.e., is
it primarily to save the effort to type ".html" for every URL, and/or is it
so the same URL can refer to a document or subdir, etc.)?
Just wondering, er, wandering in my endless quest for knowledge ....
----------------------------------------------
2. Protocol analyzer for internal modem?
3. command to display filenames for a particular month
4. Convert vc file format to Lotus 1-2-3 file format?
5. command > filename when command needs keyboard input - HOW?
6. Splitting an image in half (into two images) from a script
7. change from DISPLAY 0 to DISPLAY 1 without CTRL+ALT+F?
8. Another simple newbie question...
10. apache + frontpage extensions: problems with filenames
11. Extracting the filename extension
12. long filename extensions? HELP!!
13. Bourne shell: splitting filename into base and extension