1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to check file name format through shell script?

Discussion in 'Unix' started by Poonamol, Sep 23, 2010.

  1. Poonamol

    Poonamol New Member

    Joined:
    Mar 31, 2010
    Messages:
    33
    Likes Received:
    0
    Trophy Points:
    0
    Hello,

    I had written a shell script that accepts input file as cmd line argument and process this file.
    Code:
    if [ $# -eq 1 ]; then
    if [ -f $1 ]; then
       . $1
       LOGFILE="$LOG_FILE/MIG_BIOS.log";
          get_input_file
    
    else
       ERROR_CODE=MSCRM0005_003
       error "$ERROR_CODE : Input file $1 is not available";
       exit 1
    fi
    else
    echo "usage : $usage";
    fi
    
    I want a help in writting a get_input_file function which checks for file name format.
    My input file name format is MIG_CR_<TYPE>_<TIMESTAMP>.<EXT>
    Code:
    get_input_file()
    {
    FILE = '$1'
    #checking file exist or not
    if [ ! -f $FILE ]; then
       echo "$FILE : does not exists"
       exit 1
    elif [ ! -r $FILE ]; then
       echo "$FILE: can not read"
       exit 2
    fi
    // TO do
    // check file name format is correct or not
    }
    
    Can anyone tell me how can I check the format of file name?
    Please help me out. Thanks in advance. :eek:
     
    Last edited by a moderator: Sep 23, 2010

Share This Page