extract characters from file name - script

trying to extract the numbers in this file name:

fname="ebcdic.f0633.cmp_ebcdic.f0633.bin"
fnametmp=${fname#*[_.](V|v|F|f)}
parse=${fnametmp%%[_.](ENC|enc|CMP|cmp|BIN|bin)}}
echo FLRECL=$parse

result is FLRECL=0633.cmp_ebcdic.f0633

expected result FLRECL=0633

my guru is on holiday and i need to get this running today. any help is appreciated.

I see two numbers in file name. If you need to extract only 1st no then:

 
parse=$(echo $fname | sed 's/[^0-9]*\([0-9][0-9]*\)[^ ]*/\1/')
echo FLRECL=$parse

that works, but it also picks up the first number it encounters.

fname="reddogssamsfile1.f0633.bin"
fnametmp=${fname#*[_.](V|v|F|f)}
parse=$(echo $fname | sed 's/[^0-9]*\([0-9][0-9]*\)[^ ]*/\1/')
echo FLRECL=$parse

result:FLRECL=1

essentially, i need to grab 4 numbers after f and before BIN/CMP/ENC extensions.

appreciated

YMMV

echo "reddogssamsfile1.f0633.bin" | sed 's/.*f\([^.][^.]*\)[.].*/\1/'

worked...thank u

hi,
just curious ,

echo "samplefile1.f0633.bin" | sed 's/.*\.[a-z]*\([0-9][0-9]*\)\.[bin|cmp|enc]/\1/'

output :

0633in

i couldn't find the reason why i didn't get 0633 :frowning: