7

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?

4 Answers 4

9
$ basename a.txt.name .name
a.txt
Sign up to request clarification or add additional context in comments.

Comments

4
$ file="a.txt.name"
$ file="${file%.*}"
$ echo "$file"
a.txt

Comments

2

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

ls * | cut -d. -f1,2

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.