Find the answer to your Linux question:
Results 1 to 4 of 4
Hello, I would like to know what is the extension of a file For example filename="file.txt" I'd like to put "txt" in a variable called ext I see in an ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2008
    Posts
    6

    How to get file extension (without the dot) ?


    Hello,

    I would like to know what is the extension of a file

    For example
    filename="file.txt"

    I'd like to put "txt" in a variable called ext

    I see in an other post
    http://www.linuxforums.org/forum/lin...xtensions.html
    echo <filename> | grep -o '\.[^.]*$'

    So I think I need to do something like
    ext=`echo $filename | grep -o '\.[^.]*$'`

    But I don't know how I should modify this to avoid the dot of ".txt"
    and to get only "txt" in $ext.


    Kind regards

  2. #2
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    if you are on bash
    Code:
    # a=file.txt
    # echo ${a/*./}
    txt

  3. #3
    Just Joined!
    Join Date
    Aug 2008
    Posts
    6
    Thanks a lot
    I also have post the same question at
    How to get file extension (without the dot) - LinuxQuestions.org
    with differents answers

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Newbie
    Join Date
    Jul 2008
    Posts
    181
    This is Unix. There are many ways to get a thing done. That's why some love it and others hate it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •