Home > Archive > AWK > March 2007 > Newbie question.
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]
|
|
| chris.bailes@myrealbox.com 2007-02-14, 7:57 am |
| Hi guys,
Hi do I filter non-floating point characters (numerical plus the
decimal place) within AWK?
Typical values are:
94.2
94.0
1.05
0.003
0/
I am attempting:
echo result | awk '{gsub (/^([^0-9]|[^\n])/,"",$1} END {print $1}'
But I am finding it is truncating the first character in every
instance, and not find removing the back-slash.
Can anyone advise as to where I am going wrong?
All best,
Chris B.
| |
| Ed Morton 2007-02-14, 7:57 am |
| chris.bailes@myrealbox.com wrote:
> Hi guys,
>
> Hi do I filter non-floating point characters (numerical plus the
> decimal place) within AWK?
>
> Typical values are:
> 94.2
> 94.0
> 1.05
> 0.003
> 0/
>
> I am attempting:
>
> echo result | awk '{gsub (/^([^0-9]|[^\n])/,"",$1} END {print $1}'
^ = start of string, followed by
([^0-9] = any nun-numerical character
| = or
[^\n]) = any non-end-of-line character
There cannot be an end-of-line character in your string, since the
default record separator is the end of line, so "[^\n]" is equivalent to
".", i.e. any character. Since "any character" is a superset of "any
non-numerical character, you could have just written your pattern as
"/^./" instead of "/^([^0-9]|[^\n])/"
> But I am finding it is truncating the first character in every
> instance, and not find removing the back-slash.
>
> Can anyone advise as to where I am going wrong?
Are you just trying to find floating point numbers in your input? If so,
all you need is:
awk '/^[0-9]+\.[0-9]+$/'
Regards,
Ed.
| |
| Chris UK 2007-02-14, 7:57 am |
| On 14 Feb, 13:09, Ed Morton <mor...@lsupcaemnt.com> wrote:
> chris.bai...@myrealbox.com wrote:
>
>
>
>
>
> ^ = start of string, followed by
> ([^0-9] = any nun-numerical character
> | = or
> [^\n]) = any non-end-of-line character
>
> There cannot be an end-of-line character in your string, since the
> default record separator is the end of line, so "[^\n]" is equivalent to
> ".", i.e. any character. Since "any character" is a superset of "any
> non-numerical character, you could have just written your pattern as
> "/^./" instead of "/^([^0-9]|[^\n])/"
>
>
>
> Are you just trying to find floating point numbers in your input? If so,
> all you need is:
>
> awk '/^[0-9]+\.[0-9]+$/'
>
> Regards,
>
> Ed.- Hide quoted text -
>
> - Show quoted text -
Hi Ed,
Apologies for double-posting.
I have a string that contains what I believe to be a floating point
number, but it may contain additional characters as it is previously
split at a word boundary (typical results might be "91.2/", "$10",
"15%").
I am wanting to return a floating point number only (that is /[0-9]/
or /[\.]/) for numerical comparison within awk to a purely numerical
minimum and maximum set of limits.
Many thanks.
All best,
Chris.
| |
|
|
|
|
|