extracting matched pattern from a line using sed

I am trying to pull certain pieces of data out of a line of a file that matches a certain pattern:

[0-9][0-9][.][0-9]

The three pieces that I want to pull out of this line are the only occurrences of that pattern within the line, but the rest of the line is not consistent in each file. Basically the line is the output of uptime, which could be any of the following:

15:11:53 up 3 days, 23:44, 1 user, load average: 0.00, 0.00, 0.00

15:12:10 up 21:24, 1 user, load average: 0.00, 0.00, 0.00

15:12:04 up 1 day, 10 min, 0 users, load average: 0.00, 0.00, 0.00

Even though those examples are all boring (with 0.00 load on all cases) I need to pull out those numbers and put them into separate variables.

I assumed I could do this with sed (mostly because I know sed better than awk or grep) but I have been struggling for a while and would like some guidance...

I have seen plenty of search results dealing with deleting lines that contained the pattern or ones that didn't contain the patters, but nothing about keeping just parts of a line that match the pattern.

I even tried deleting everything in the line that DID NOT match that patters, but that didn't pan out either.

Any suggestions?

Hi, your pattern does not seem to match load averages:
[0-9][0-9][.][0-9] vs. [0-9].[0-9][0-9]

E.g.
ksh:

echo $line grep -o "\b[0-9]\.[0-9][0-9]"|xargs -n3|read avgload1min avgload5min avgload15min
echo $avgload1min $avgload5min $avgload15min
0.00 0.00 0.00

or

line="15:11:53 up 3 days, 23:44, 1 user, load average: 0.00, 0.00, 0.00"

bash:

read avgload1min avgload5min avgload15min < <(echo $line grep -o "\b[0-9]\.[0-9][0-9]" |xargs -n3)
echo $avgload1min $avgload5min $avgload15min
0.00 0.00 0.00

Instead of

grep -o "\b[0-9]\.[0-9][0-9]"|xargs -n3

you could also use

sed 's/.*e: //;s/,//g'

so:

echo $line sed 's/.*e: //;s/,//g'|read avgload1min avgload5min avgload15min

cat > abc.txt
15:11:53 up 3 days, 23:44, 1 user, load average: 0.00, 0.00, 0.00

15:12:10 up 21:24, 1 user, load average: 0.00, 0.00, 0.00

15:12:04 up 1 day, 10 min, 0 users, load average: 0.00, 0.00, 0.00[/html]

cat abc.txt | perl -e 'while (<>){ chomp; my @cols = split(":");($l1,$l2,$l3) = split(/,/,$cols[-1]); print "$l1\t$l2\t$l3\n";}'
0.00 0.00 0.00

0.00 0.00 0.00

0.00 0.00 0.00

Use the variables which are needed ie l1 or l2 or l3 according to your need

Hope this helps .

Cheers

if you wanna take out last three fields..

awk '{gsub(",","")}{print $NF" "$(NF-1)" "$(NF-2)}' filename|read $var1 $var2 $var3