Extracting 10 digit number from txt files

Hi,

Was wondering if you could give me an example of extracting a 10 digit number from 5 txt files using a regular expression (the number is always different ) and storing the numbers in variables

Thanks

C19

What you have attempted so far? It sounds like homework.

Not quite homework!, i'm a developer for Barclays bank, shell scripting is new to me, and wondered about regular expressions, I've just ordered Shells by example, hopefully that should point me in the right direction...

Try this:

your_variable=`cat t1.txt t2.txt t3.txt t4.txt t5.txt | sed -n -e 's/.*\([0-9]\{10\}\).*/\1/p'`

once again..... why do you need 'cat'?

send the contents of the files (1 -5) to sed command for processing.

vgersh99's point is that cat is not necessary since sed can read from multiple files. It's the whole UUoC (useless use of cat) idea.

I agree - it's up to you. I like to use cat to pipe everything to next command. The above command is the same as following:

sed -n -e 's/.*\([0-9]\{10\}\).*/\1/p' t1.txt t2.txt t3.txt t4.txt t5.txt

I'd suggest reading the posted link to UUoC or this one.

BTW......

sed -n -e 's/.*\([0-9]\{10\}\).*/\1/p' t[1-5].txt

Also BTW, if you need to check for only 10 character numbers, on word boundaries, this alternative may narrow the scope:

sed -n -e 's/\(\<[0-9]\{10\}\>\)/\1/p'