Find the answer to your Linux question:
Results 1 to 3 of 3
I have a filename file-name-here-1.2.3-i486-2.tar I would like to know how to remove the last two fields leaving only: file-name-here-1.2.3 I can use: x=file-name-here-1.2.3-i486-2.tar echo ${a%-*} to remove the last ...
  1. #1
    Just Joined!
    Join Date
    Feb 2005
    Posts
    14

    [SOLVED] How to remove last two fields

    I have a filename
    file-name-here-1.2.3-i486-2.tar

    I would like to know how to remove the last two fields leaving only:
    file-name-here-1.2.3

    I can use:
    x=file-name-here-1.2.3-i486-2.tar
    echo ${a%-*}

    to remove the last field (after -) but how do i remove the last two in one fell swoop?

    Thank you gurus

  2. #2
    Linux Newbie
    Join Date
    Sep 2004
    Location
    UK
    Posts
    160
    echo ${x%-*-*}
    or
    echo ${x%-i*}
    In a world without walls and fences, who needs Windows and Gates?

  3. #3
    Just Joined!
    Join Date
    Feb 2005
    Posts
    14
    Beautiful. Thanks a bunch.

Posting Permissions

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