Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using test with wildcards 3

Status
Not open for further replies.

johngiggs

Technical User
Oct 30, 2002
492
US
I have the following script which I am using to add volumes to different files, but I'm not sure how to go about using test with wildcards.

#!/bin/ksh
while read TAPELIST
do
TAPEPREFIX=`echo $TAPELIST |cut -c 1-3`
TAPESERIES=`echo $TAPELIST |cut -c 4-6`
TAPENUM=`echo $TAPELIST |cut -c 1-6`
if [ $TAPEPREFIX = "509" ] && [ $TAPESERIES != "3[0-9][0-9]" ]
then
echo $TAPELIST >> TNTN.$TODAY
else
if [ $TAPEPREFIX = "700" ]
then
echo $TAPELIST >> MTV.$TODAY
else
echo $TAPELIST >> NDHM.$TODAY
fi
fi
done

I would like to make the following line work so that if the value of $TAPESERIES is 3 followed by two more numbers, it will not go to TNTN.$TODAY.

if [ $TAPEPREFIX = "509" ] && [ $TAPESERIES != "3[0-9][0-9]" ]

I tried using "3??" and "3*", but they did not work. Any help would be greatly appreciated.

Thanks,

John
 
You need to use the Korn shell version of test, with the double brackets, and not surround the pattern with speech marks, e.g.

Code:
if [[ $TAPEPREFIX = 509 ]] && [[ $TAPESERIES != 3[0-9][0-9] ]]


Annihilannic.
 
OR:

if [[ $TAPEPREFIX = 509 ]] && [[ $TAPESERIES != @(3[0-9][0-9]) ]]

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Thanks Annihilannic & vgersh99!! Both of your solutions work!! If I did in fact want to do it with the Bourne shell, how could I do that?

Thanks,

John
 
Code:
if echo $TAPEPREFIX | grep -w &quot;3[0-9][0-9]&quot; > /dev/null

... is one possible option. Some greps can use -q instead of redirecting to null.

Annihilannic.
 
Might be simpler to use case....
[tt]
case $TAPENUM in
509[!3]*) echo TNTN ;;
700*) echo MTV ;;
*) echo NHTM ;;
esac
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top