Home > Archive > AWK > November 2004 > Beginner - Replace Field
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Beginner - Replace Field
|
|
| python1 2004-11-17, 8:55 pm |
| I'd like to replace all non-numbers in a field with blanks. A sample of
the field is '100-Test', where the '100' should be the only thing left
in the field when the substitution has completed.
I've tried the following:
{sub(/[^0-9]*/,"",$24);print}
....but it does not seem to remove the non-numbers. I assume there is
something wrong with my logic here, but am not 'seeing' it.
Please assist.
| |
| Bob Harris 2004-11-17, 8:55 pm |
| In article <cngnaq0ro5@enews1.newsguy.com>,
python1 <python1@spamless.net> wrote:
> I'd like to replace all non-numbers in a field with blanks. A sample of
> the field is '100-Test', where the '100' should be the only thing left
> in the field when the substitution has completed.
>
> I've tried the following:
>
> {sub(/[^0-9]*/,"",$24);print}
>
> ...but it does not seem to remove the non-numbers. I assume there is
> something wrong with my logic here, but am not 'seeing' it.
>
> Please assist.
gsub vs sub
{gsub(/[^0-9]/,"",$24);print}
Bob Harris
| |
| python1 2004-11-18, 3:56 pm |
| Bob Harris wrote:
> gsub vs sub
>
> {gsub(/[^0-9]/,"",$24);print}
>
> Bob Harris
Works great. Thanks.
|
|
|
|
|