Reputation: 11817
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?
Upvotes: 7
Views: 5292
Reputation: 301
If naming convention is always foo.bar.other , then this is simple enough:
ls * | cut -d. -f1,2
Upvotes: 2
Reputation: 13471
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
Upvotes: 1
Reputation: 360345
$ file="a.txt.name"
$ file="${file%.*}"
$ echo "$file"
a.txt
Upvotes: 4