Get file name before extension

I have several files in the same directory (on a UNIX file system) that looks like this:

a.txt.name b.xml.name c.properties.name a.txt.name2 b.xml.name2 c.properties.name2 

How do I get a string before the name or name2 with some shell command?

i.e. a.txt , b.xml , c.properties part?

+7
linux unix bash shell
source share
4 answers
 $ basename a.txt.name .name a.txt 
+9
source share
 $ file="a.txt.name" $ file="${file%.*}" $ echo "$file" a.txt 
+4
source share

If the naming convention is always foo.bar.other, then this is simple enough:

 ls * | cut -d. -f1,2 
+2
source share

Take a look at the bash string processing functions. This page should help you mainly:

http://tldp.org/LDP/abs/html/string-manipulation.html

+1
source share

All Articles