Find the answer to your Linux question:
Results 1 to 5 of 5
Hi There Guru's! I am writing a simple script to move application program files between a live and test environment. Each file can have either a .i extension, or a ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jan 2006
    Posts
    1

    Newbie scripting - file extensions..


    Hi There Guru's!

    I am writing a simple script to move application program files between a live and test environment. Each file can have either a .i extension, or a .p and a .r (source and x-coded). The x-coded file goes to a directory which starts with the same two letters, thus:

    /apps/live/src
    /apps/live/us/ap
    /apps/live/us/br
    etc


    Source Name = apvomt.p
    Compile Name = apvotmp.r

    I have managed to create the script which moves the files, provided they are a .p extension, but I now need to check if the extension is a .i

    How do I just pick up the last 2 characters of the filename - can I use CUT, or is there another way?

    Many thanks

    SD

  2. #2
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    Provided you're using bash and not some other shell, there's a syntax for cutting in variables (maybe other shells can do it as well, but I haven't tried, so I don't know how compatible it is). It looks like this:
    Code:
    a=somefile.foo
    ext="${a##*.}"
    echo "$ext"       # This will echo "foo"

  3. #3
    Linux User muha's Avatar
    Join Date
    Jan 2006
    Posts
    290
    moeh :?
    Either i don't get what yout getting at or you could yield:
    mv *.i ./some_dir_down/

    the ./ means 'relative from the current dir'

    You could also do:
    mv *.i ../some_dir_next_to/
    to move them to the dir next to the current one.

  4. #4
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    Use case:
    Code:
    case $file in
       *.i)    # code for the .i files
               # blah
               # blah
               ;;
        *.p)  # code for the .p files
               # blah
               # blah
               ;;
    ...etc ...
    esac

  5. #5
    Linux User muha's Avatar
    Join Date
    Jan 2006
    Posts
    290
    more info on writing proper scripts: (like scm's) ~> http://www.linuxcommand.org/

Posting Permissions

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