-1

I have files with "multiple" extension , for better manipulation I would like to create new folder for each last extension but first I need to retrieve the last extension.

Just for example lets assume i have file called info.tar.tbz2 how could I get "tbz2" ?

One way that comes to my mind is using cut -d "." but in this case I would need to specify -f parameter of the last column, which I don't know how to achieve.

What is the fastest way to do it?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Darlyn
  • 4,715
  • 12
  • 40
  • 90
  • 1
    `f=info.tar.tbz2; ext=${f##*.}`, to put everything after the last `.` into `ext` without the performance expense of external tools such as `awk` or `sed`. – Charles Duffy Nov 17 '15 at 00:28

1 Answers1

2

You may use awk,

awk -F. '{print $NF}' file

or

sed,

$ echo 'info.tar.tbz2' | awk -F. '{print $NF}'
tbz2
$ echo 'info.tar.tbz2' | sed 's/.*\.//'
tbz2
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274