Reputation: 12370
My input is a large list of files. They could have any characters in the name (including periods, because there are some package names as well). Here's some small sample input:
com.test.impl.servlets.Test.xml
TestClass.class
TestClass1.class
Test2.java
Test3.java
I want to know all of the different file extensions in my list, so essentially, I want egrep -o everything after the last period. Something like this:
input | xargs <unknown command but probably egrep> | sort -u
Would return:
.xml
.class
.java
Upvotes: 0
Views: 152
Reputation: 65791
You can try grep -o '\.[^.]*$'
:
$ echo 'com.test.impl.servlets.Test.xml
TestClass.class
TestClass1.class
Test2.java
Test3.java' | grep -o '\.[^.]*$' | sort -u
.class
.java
.xml
or sed 's/.*\././'
:
$ echo 'com.test.impl.servlets.Test.xml
TestClass.class
TestClass1.class
Test2.java
Test3.java' | sed 's/.*\././' | sort -u
.class
.java
.xml
Upvotes: 3