Multiple repetitions

In the below example, sed will consider the first field and prints it to twice..

% echo "123 abc" | sed 's/[0-9]*/& &/'
123 123 abc

Suppose if the input given is "123 abc def 345" then also it will consider only the 1st field.

If I require output as "123 abc def 345 345" i.e, sed should convert the given field where ever it is.

% echo "123 abc def 345" | sed 's/[0-9]*/& &/'

My expected output should be :

123 abc def 345 345

Can you please help me ?

Thanks in advance...

% echo "123 abc def 345" | perl -e '$x=<>;$x=~s/(.* )([0-9]+)/$1$2 $2/; print $x'
123 abc def 345 345

Thanks balajesuri

But could you please answer the same in sed?

in awk ..

$ echo "123 abc def 345" | nawk '{$NF=$NF" "$NF; print}'
123 abc def 345 345
echo "123 abc def 345" | sed 's/\(.* \)\([0-9]*\)/\1\2 \2/g'

---------- Post updated at 12:55 ---------- Previous update was at 12:49 ----------

@giridhar276: The above sed would repeat the last found number only if it is at the end of string. Use Perl's one-liner. It should work on all *nix systems.

@jayan_jay: I think giridhar276's requirement is to repeat the last found number in string. So if the string is "123 abc def 345 pqr", output should be "123 abc def 345 345 pqr".

Am I right giridhar276?

try this.

echo "123 abc def 345" | sed 's/[0-9]\+/& &/2g'