1

Playing around with awk I noticed this behavior:

[root@ror6ax3 ~]# grep open * | awk '$2 ~ /opens*/ {print $0}'
install.log:Installing openldap-2.4.23-32.el6_4.1.x86_64
install.log:Installing openssl-1.0.1e-15.el6.x86_64
install.log:Installing openssh-5.3p1-94.el6.x86_64
install.log:Installing openssh-clients-5.3p1-94.el6.x86_64
install.log:Installing openssh-server-5.3p1-94.el6.x86_64
install.log:Installing b43-openfwwf-5.2-4.el6.noarch
[root@ror6ax3 ~]# grep open * | awk '$2 ~ /opens */ {print $0}'
install.log:Installing openssl-1.0.1e-15.el6.x86_64
install.log:Installing openssh-5.3p1-94.el6.x86_64
install.log:Installing openssh-clients-5.3p1-94.el6.x86_64
install.log:Installing openssh-server-5.3p1-94.el6.x86_64

Why would opens* match openldap ?

3

* means 0 or more, so effecively 0 or more s characters. There's the documentation here, that says

For example, ph*' applies the*' symbol to the preceding h' and looks for matches of onep' followed by any number of h's. This also matches justp' if no `h's are present.

In your case, you're doing opens* while you're probably expecting something like opens+, where + means "1 or more". Check out the docs on the + operator here

  • Got it, I confused * with +. – kaboom Jul 11 '14 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.