extracting only numerals from string.

Hi!!!

i have two files "tushar20090429200000.txt" and "tushar_err20090429200000.txt"

The numeric part here is date and time.
So this part of file keeps changing after every hour.
I want to extract the numeric part from the both file names and compare them whether they are equal or not.

thanks in Advance....:o

Try tghis

script.sh

var1=`echo $1 | sed -e 's/[:alpha:]//g' -e 's/\.//g'`
var2=`echo $2 | sed -e 's/[:alpha:]//g' -e 's/\.//g'`

if [ "$var1" == "$var2" ]; then
echo "Files equal"
else
echo "not equal"
fi

run as

script.sh tushar20090429200000.txt tushar_err20090429200000.txt

cheers,
Devaraj Takhellambam

no need to call external sed if using bash

a=tushar20090429200000.txt
b=tushar_err20090429200000.txt
if [  ${a//[a-zA-Z.]/} = ${b//[a-zA-Z._]/} ] then
 ....
fi

I cant run it as a separate script.
i have to use this logic in a script.
Kindly suggest something else in shell or awk.

Try this. Not tested

awk 'BEGIN{
match($a,/[0-9]+/);v1=substr($a,RSTART,index($a,".")-RSTART)
match($b,/[0-9]+/);v2=substr($b,RSTART,index($b,".")-RSTART)
if ( v1 = v2 )print "Files Match"
print "Files dont match"
}' a="tushar20090429200000.txt" b="tushar_err20090429200000.txt"

cheers,
Devaraj Takhellambam