Help with sed

Hi Guys,

I know this is probably really easy but I've just started learning the basics of this stuff.

Im trying to extract the number from a whole bunch of filesnames and store then as variables in my bash script.

So for instance my filename is dim24.15c.07/junk/altmag6082Jb7J1f5.txt, all the characters are fixed from one file name to the next but the numbers vary, I need to get the number out, I'm reading the sed manual, anybody know the answer quickly?

If you want to sort 6082Jb7J1f5 from dim24.15c.07/junk/altmag6082Jb7J1f5.txt with altmag fixed, you can do this :

file=dim24.15c.07/junk/altmag6082Jb7J1f5.txt

number=$(basename $file .txt | cut -c7-)

echo $number

Well sort of, the problem is I dont know how many number I need or anything else really. The only thing I have is the "template" dimxxyyczz/junk/altmaga...kJbfJ1fc.txt

Im trying to extract xx,yy,zz,a...k,c so I can use them as variables.

Please give us an example, I don't understand which part of the pathname you want to extract ??? :confused:

Apologies, basically Im trying to extract each number and set a variable equal to its value.

file=dim24.15c.07/junk/altmag6082Jb7J1f5.txt

So I need some like $a = .15, $b = .07, $c=6082, $d = 7, $e = 1, $f = 5 in this case.

Thanks for you help. Its greatly appreciated.

if "." is not needed.

# file=dim24.15c.07/junk/altmag6082Jb7J1f5.txt
# set -- `echo $file | tr -s '[a-zA-Z/.]' ' '`
# echo $1
24
# echo $2
15

Brilliant! Works perfectly. Thanks!:b: