views:

80

answers:

4

I have some files in the same directory (in UNIX filesystem) that looks like:

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

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

How do I get the string before the name or name2 part using some shell command?

ie. the a.txt, b.xml, c.properties part?

+7  A: 
$ basename a.txt.name .name
a.txt
Thomas
Nice suffix option. Thanks!
Kaleb Pederson
+1  A: 

Take a look at the bash string manipulation functions. This page should get you most of the way there:

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

HTH, Steve

Steve Robillard
+2  A: 
$ file="a.txt.name"
$ file="${file%.*}"
$ echo "$file"
a.txt
Dennis Williamson
A: 

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

ls * | cut -d. -f1,2

DaveG