write a shell script that check file name like pstat_24.txt (up to 5 digits) i mean to say this digit can be range from 1 to 99999 only
correct file name are
pstat_10000.txt pstat_12345.txt pstat_14569.txt
wrong file name are
pstat_1234567.txt pstat_1a2345.txt pstat_1ss123.txt
Thanks Mayank
pls make sure that you read the rules first.
pls elaborate on the problems you're having so that we all can be of help.
From what I could understand, this should do it.
#! /bin/sh FILE="pstat_24.txt" FILE=${FILE%.txt} NUM=${FILE##*_} if [[ $NUM = *[a-zA-Z]* ]] ; then echo "Not A Valid Name" elif [ $NUM -gt 1 -a $NUM -lt 100000 ] ; then echo "Name is good" else echo "Bad choice for a name" fi
Tested for
FILE="pstat_24.txt" FILE="dadasd_342f.txt" FILE="dadasd_34223434.txt" FILE="dadasd_0.txt" FILE="dadasd.txt"
Vino