Click here to Skip to main content
15,888,007 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I had written a shell script that accepts input file as cmd line argument and process this file.
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>
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 foramt is correct or not
}

Can anyone tell me how can I check the format of file name?
Please help me out. Thanks in advance.
Posted
Updated 23-Sep-10 0:20am
v3
Comments
Sandeep Mewara 23-Sep-10 6:20am    
PRE tags are your friends. Use it for formatting code part. It makes your question readable.

1 solution

A method I can think of is:

1. store the filename in a temporary file
Echo $FILE > filename.tmp

2. Use findstr with the proper regex to test the search string in the temporary file.

At this link you find a good reference of the findstr command and how to create the regex to test the filename:

http://www.computerhope.com/findstr.htm[^]

Good luck!
 
Share this answer
 
v2
Comments
E.F. Nijboer 23-Sep-10 9:31am    
Thanks for reply.

For 1st option, If I use

FILE=`$1`
TMP=`echo $input_file | cut -d "_"; -f 1-4`
EXTN=`echo $input_file | cut -d "."; -f 5`

Will it work?

I am not able to open the link you have provided, I am getting 404 Error.
E.F. Nijboer 23-Sep-10 9:34am    
First I deleted your answer and added it as a comment.

The copy-paste action didn't completely went well because the characters "tm" didn't come along. The link is fixed and should now work properly.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900