Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

echo "123f69,"|awk '$0 !~ /[A-Z]*/'

6 views
Skip to first unread message

Hongyi Zhao

unread,
Apr 11, 2015, 9:23:27 AM4/11/15
to
Hi all,

Perhaps it's a simple issue for here, but I cann't figure out it. Sorry
for bothering again.

See the following for detail:

werner@debian:~$ echo "123f69,"|awk '$0 !~ /[A-Z]*/'
werner@debian:~$ echo "123f69,"|awk '$0 !~ /[A-Z]+/'
123f69,

Why the first one gives nothing, while the second one will output the
original string?

According to REGEXP used here, I want awk print the line which doesn’t
contain the upper case A-Z. In this sense, I think the above two methods
are equivalent, but why they give different results?

Regards
--
.: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.

Kenny McCormack

unread,
Apr 11, 2015, 9:26:48 AM4/11/15
to
In article <mgb78a$6dj$1...@aspen.stu.neva.ru>,
Hongyi Zhao <hongy...@gmail.com> wrote:
>Hi all,
>
>Perhaps it's a simple issue for here, but I cann't figure out it. Sorry
>for bothering again.
>
>See the following for detail:
>
>werner@debian:~$ echo "123f69,"|awk '$0 !~ /[A-Z]*/'
>werner@debian:~$ echo "123f69,"|awk '$0 !~ /[A-Z]+/'
>123f69,
>
>Why the first one gives nothing, while the second one will output the
>original string?

Ask yourself this question:

Does the string "123f69," contain any sequences of zero or more upper
case letters?

--

Some of the more common characteristics of Asperger syndrome include:

* Inability to think in abstract ways (eg: puns, jokes, sarcasm, etc)
* Difficulties in empathising with others
* Problems with understanding another person's point of view
* Hampered conversational ability
* Problems with controlling feelings such as anger, depression
and anxiety
* Adherence to routines and schedules, and stress if expected routine
is disrupted
* Inability to manage appropriate social conduct
* Delayed understanding of sexual codes of conduct
* A narrow field of interests. For example a person with Asperger
syndrome may focus on learning all there is to know about
baseball statistics, politics or television shows.
* Anger and aggression when things do not happen as they want
* Sensitivity to criticism
* Eccentricity
* Behaviour varies from mildly unusual to quite aggressive
and difficult

Hongyi Zhao

unread,
Apr 11, 2015, 9:52:04 AM4/11/15
to
On Sat, 11 Apr 2015 13:26:44 +0000, Kenny McCormack wrote:

> Ask yourself this question:
>
> Does the string "123f69," contain any sequences of zero or more
> upper case letters?

OMG, it contains zero time sequences of upper case letters, so it doesn't
contains zero time sequences of upper case letters.

Ed Morton

unread,
Apr 11, 2015, 10:31:29 AM4/11/15
to
On 4/11/2015 8:23 AM, Hongyi Zhao wrote:
> Hi all,
>
> Perhaps it's a simple issue for here, but I cann't figure out it. Sorry
> for bothering again.
>
> See the following for detail:
>
> werner@debian:~$ echo "123f69,"|awk '$0 !~ /[A-Z]*/'
> werner@debian:~$ echo "123f69,"|awk '$0 !~ /[A-Z]+/'
> 123f69,
>
> Why the first one gives nothing, while the second one will output the
> original string?

Ask yourself - what does `*` mean vs what `+` means? Rewrite your conditions as:

awk '/[A-Z]*/{next} 1'
awk '/[A-Z]+/{next} 1'

Now do you see it? How about the equivalent:

awk '/[A-Z]{0,}/{next} 1'
awk '/[A-Z]{1,}/{next} 1'

or:

awk '/[A-Z]?/{next} 1'
awk '/[A-Z]/{next} 1'

>
> According to REGEXP used here, I want awk print the line which doesn’t
> contain the upper case A-Z. In this sense, I think the above two methods
> are equivalent, but why they give different results?

Because they aren't equivalent.

Some other points:

`[A-Z]` is not necessarily just the upper case letters. In some locales A-Z
means `AbBcC...zZ`, i.e. all letters except "a". That's what the character class
[:upper:] is for.

You don't need to write `$0 ~ ` in a condition as that's the default. You could
just write awk '!/[[:upper:]]/'.

I hate that I responded to this but I couldn't stop myself. Oh well, maybe I'll
get employee of the month....

Ed.

Hongyi Zhao

unread,
Apr 11, 2015, 7:07:36 PM4/11/15
to
On Sat, 11 Apr 2015 09:31:23 -0500, Ed Morton wrote:

[snip]

> I hate that I responded to this but I couldn't stop myself. Oh well,
> maybe I'll get employee of the month....

Surely, I also think so ;-)

Regards
>
> Ed.

Ed Morton

unread,
Apr 11, 2015, 11:30:43 PM4/11/15
to
On 4/11/2015 6:07 PM, Hongyi Zhao wrote:
> On Sat, 11 Apr 2015 09:31:23 -0500, Ed Morton wrote:
>
> [snip]
>
>> I hate that I responded to this but I couldn't stop myself. Oh well,
>> maybe I'll get employee of the month....
>
> Surely, I also think so ;-)
>


I'm not sure if I've been employed or assimilated. I tried to resist but....

12 of 27.

frank.w...@gmail.com

unread,
Apr 12, 2015, 3:42:46 AM4/12/15
to
From EdMorton:
> I hate that I responded to this but I couldn't stop myself. Oh well,
> maybe I'll get employee of the month....

Our tasking has changed from that of servants to that of
educators, so your employment is now more honorable.

Frank

Kaz Kylheku

unread,
Apr 12, 2015, 10:01:50 AM4/12/15
to
If you're educating others to be servants, though, then that is hardly more
honorable than being one.

Frank P. Westlake

unread,
Apr 12, 2015, 10:53:32 AM4/12/15
to
That has no relevancy to any current discussion so I don't know why you
state it.

Frank

Javier

unread,
Apr 12, 2015, 6:53:45 PM4/12/15
to
> awk '/[A-Z]*/{next} 1'

May I ask what does the '1' at the end mean?

Janis Papanagnou

unread,
Apr 12, 2015, 7:13:22 PM4/12/15
to
Am 13.04.2015 um 00:53 schrieb Javier:
>> awk '/[A-Z]*/{next} 1'
>
> May I ask what does the '1' at the end mean?

It's a shortcut to print the current line.

awk '
/[A-Z]*/{next}
1
'

Syntax: condition { action }

Condition "1" means 'true', and the default action is 'print $0'.

Janis

Chris F.A. Johnson

unread,
Apr 12, 2015, 8:08:08 PM4/12/15
to
On 2015-04-12, Javier wrote:
>> awk '/[A-Z]*/{next} 1'
>
> May I ask what does the '1' at the end mean?

It's a non-zero pattern, so the line is printed.

--
Chris F.A. Johnson
0 new messages