Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get file name before the extension

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?

like image 555
ryanprayogo Avatar asked May 04 '10 16:05

ryanprayogo


3 Answers

$ basename a.txt.name .name
a.txt
like image 168
Thomas Avatar answered Sep 20 '22 18:09

Thomas


$ file="a.txt.name"
$ file="${file%.*}"
$ echo "$file"
a.txt
like image 28
Dennis Williamson Avatar answered Sep 19 '22 18:09

Dennis Williamson


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

ls * | cut -d. -f1,2
like image 36
DaveG Avatar answered Sep 20 '22 18:09

DaveG