I have 3 types of files. The names of which starts with P,I,M
like P*********
D*********
M*********
now I need to do some operations witht hese files..
so
if file name starts with P or p
then
do the operation for P file...
fi
else
if file name starts with I or i
then
do the operation for I file...
fi
else
if file name starts with M or m
then
do the operation for M file...
fi
please help me in doing so..
input is file name... which is case sensitive.. and after P or I or M everything is numbers..like P12345 etc...
if [[ "${FILENAME:0:1}" = [Ii] ]]
then do something
elif [[ "${FILENAME:0:1}" = [Mm] ]]
then do something
elif [[ "${FILENAME:0:1}" = [Pp] ]]
then do something
fi
but using case is cleaner.
Or explain more precisely what you want to do, maybe one can find the optimal code for doing so.
!#/us/bin/ksh
ls -1 P* >Pfile.lst
ls -1 D* >Dfile.lst
ls -1 R* >Rfile.lst
while read P D R
do
if [ -s "$P" ] then
--
fi
if [ -s "$D" ] then
-----
fi
if [-s "$R" ] then
-----
fi
done < Pfile.lst Dfile.lst Rfile.lst
The files which i have, is named like P12345 or D12345 or M12345....
The numbers with P D and M may changes.....
File name is the input...
So if i give the file name first it should check the file name.. If it is not started with P or D or M then it should give error...
If it is with the proper name then depending on whether it P D M I should do the operation....
You ppl here may tell like It is better to use CASE statement for this.. Yes it is better to use CASE but the problem is if I use case then I should write everything about that file under once statement..
But i should be able to use this manier times in my script..
So please tell me how to check equality with shell script ..
the file name can start with P or p.. that means it should not be case sensitive...
This can easily be arranged with an extra line in the case statement.
case $FILENAME in
I*|i*) i-operation ;;
M*|m*) m-operation ;;
P*|p*) p-operation ;;
*) echo "Wrong inputfile. The first character should be i, m or p. Exiting"; exit 1 ;;
esac
brother I need to use it manier times in my script.. so I want to check it with if statement..
Please tell me how can i use equality sign with if statement in shell script if the file name is not case sensitive..
i used the below one too but didnt work out..
if [[ "REQ2" -eq P* ]] && [[ "REQ2 -eq p* ]]
then
----------
fi
and also the below one
if [[ "REQ2" == P* ]] && [[ "REQ2 == p* ]]
then
----------
fi
please help me
---------- Post updated at 09:02 PM ---------- Previous update was at 08:58 PM ----------
and somebody please tell me what is the meaning of ${FILENAME:0:1}