sed doubt
I have a simple doubt in sed:
PHP Code:
PHP Code:
|
The asterisk means zero or more occurrences of the previous expression, so that it can match the null string. In this case it matches the null string at the beginning of the line (since there are no digits there) and substitutes it with itself (nothing), plus a blank space (that one between the two ampersand in the substitution string):
Code:
$ echo "abc 123" | sed 's/[0-9]*/& &/' Code:
$ echo "abc 123" | sed 's/[0-9]*/& & & & &/' |
The construct '[0-9]*' means zero or more numbers. Zero numbers is the null string. The first place a null string occurs is before the letter 'a'. This clarifies:
Code:
$ echo "abc 123" | sed 's/[0-9]*/321/' Code:
$ echo "abc 123" | sed -r 's/[0-9]+/& &/' |
Thanks a lot, I had the misunderstanding that in [0-9][0-9]* , it matches 0 or more of number.
but it matches first one digit from first [0-9] then 0 or more from 2nd [0-9]. So that it should match a number. |
All times are GMT -5. The time now is 02:54 PM. |