AIX 4.2 Korn shell and grep question

Ho do I find out the verion of the Kron shell on my client`s system ?

There is no one to ask. They are not knowledged enough (hard to believe but yes).

Also, on that AIX 4.2, I am trying to figure out how to do a grep using a search patter like below but does not seam to work. The '*' do not seam to be recognized.

"^*,3773,*,438,08..10..01,"

That would save me alot of grep from a grep from a grep ...

I'm not real sure on the ksh version, but for your grep question...

'*' in grep world is a Regular Expression operator, not the filename wildcard you're thinking of.

In Regular Expressions, a * means "match 0 or more of the previous character"...

grep 'a*bc' somefile

would match bc, abc, aabc, aaabc, aaaabc, etc...

try

print ${.sh.version}

or

what /bin/ksh | grep Version

I am not completely sure what you are really seeking: is "Kron" a typo for "Cron" or for "Korn" (shell).

I suppose it is the latter, here is a procedure:

  • switch to vi editing mode. Enter at the command line "set -o vi"
  • press "ESC" to get into command mode
  • press <CTRL>-<V> to get the version. In my case (AIX 5.2, but yours should be no different) this gives "Version M-11/16/88f"

The asterisk "" is the metacharacter for "zero or more instances of the last regular expression". You have searched for "," which means "any number (including zero) of commas". If you want to search for "any string in any length" then use ".*" The dot "." means "any character" and the asterisk multiplies this to "any length", resulting in "any character n times, where n is any number including 0".

I hope this helps.

bakunin

Sorry I meant Korn and the '*' stands for anything.

The set -o vi method produced :
Version M-11/16/88

The print ${.sh.version} method revealed to be unrecognized

teh what /bin/ksh | grep Version method revealed nothing. There is an output but no word version in it.

The records content looks like :

S(xx,xx,xx,xx,xx,xx,xx,xx,xx,...,xx,xx,999,yy/\mm/\dd,...

where the 'S' is a letter being D, A or S
where the 'xx' is either any text within commas or can be empty (meaning ,, )
where 999 is a command number
where 'yy/\mm/\dd' is a date with the '/\' characters

to my understanding, the amount of comma separated fields are constant but do not have to have data in them so they can be empty. Is it possible to do a grep search according to n-number of fields (comma separated) with some of those fields having specific values ?

my search criteria for the moment, is the command number and the date

As programing language, there only seams to be C, Bash and Korn. No Perl or anything else.

Yes, there is. We'll go through that one step at a time:

when the fields are comma-separated, then a single field would be: some (optional, the field could be empty) character(s) followed by a comma. A regular expression covering this would be:

[^,]*,

This regex would find any number of non-commas followed by a comma, in other words, one field. Lets assume now that you want to search for a specific content of the 18th field. You would have to look for 17 repetitions of this pattern followed by some value. Fortunately there is a "multiplicator" device for such occasions in regex:

\([^,]*,\)\{17\}search,

This would search for 17 repetitions of "[^,]*," (the "\(" and "\)" are grouping characters, the "\{...\}" is said repetition counter - sort-of "parameterized asterisk"), followed by "search" as the text to search for in the 18th field.

You should no be able to construct your own regexp, based on this.

I hope this helps.

bakunin

If there are empty fields (meaning "...,aaa,,bbb,..." instead of "...,aa,xxx,bbb,...) won't the grep count 2 commas instead of 1 with the [^,]* ?

The records look like this:
x(xx,x,x,,,x,x,9999,,x,,,xx,,,xxxx,,,,,,,,,,,,,,,,,,999, . . .

So to test it I simply tried with grep "^\([^,]*,\)\{7\}9999" but found nothing.

The '9999' is in the 8th field and the '999' is in the 34th one.

No. As i have elaborated on above the "[^,]" means "anything, but a comma", therefore a comma is the last thing that could be matched by it. Additionally the "" means "zero or more occurrences". For example "abc" would be matched not only by "abc" and "abbbc" but also by "ac". It would not be matched by "adc" though.

hm, that is quite astonishing. I tried exactly your data and command and it is working (here on cygwin, but that shouldn't matter):

bakunin@cygwin ~/tmp$ cat test.asc
x(xx,x,x,,,x,x,9999,,x,,,xx,,,xxxx,,,,,,,,,,,,,,,,,,999,
x(xx,x,x,,,x,x,8888,,x,,,xx,,,xxxx,,,,,,,,,,,,,,,,,,999,

bakunin@cygwin ~/tmp$ grep "^\([^,]*,\)\{7\}8888" test.asc
x(xx,x,x,,,x,x,8888,,x,,,xx,,,xxxx,,,,,,,,,,,,,,,,,,999,

bakunin@cygwin ~/tmp$ grep "^\([^,]*,\)\{7\}9999" test.asc
x(xx,x,x,,,x,x,9999,,x,,,xx,,,xxxx,,,,,,,,,,,,,,,,,,999,

bakunin@cygwin ~/tmp$ grep "^\([^,]*,\)\{33\}999" test.asc
x(xx,x,x,,,x,x,9999,,x,,,xx,,,xxxx,,,,,,,,,,,,,,,,,,999,
x(xx,x,x,,,x,x,8888,,x,,,xx,,,xxxx,,,,,,,,,,,,,,,,,,999,

bakunin@cygwin ~/tmp$ grep --version
grep (GNU grep) 2.5.1

Copyright 1988, 1992-1999, 2000, 2001 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

by the way: i have edited the thread title so that it can easier be searched for. I hope you don't mind.
bakunin

Just tried the "grep --version" and it did not produce the same output as you.

It just gave the usual grep response when it does not recognize an option and lists the general usage syntax.

Beside the AIX grep there is a second supported grep version from the IBM Linux Toolbox. I would not be suprised if those two grep programms differ just as many others like "find" "make" etc. do :wink:

Ok, i retried it on AIX - same result as in Cygwin:

bakunin@aix_5_2:/tmp> cat test.asc
x(xx,x,x,,,x,x,9999,,x,,,xx,,,xxxx,,,,,,,,,,,,,,,,,,999,
x(xx,x,x,,,x,x,8888,,x,,,xx,,,xxxx,,,,,,,,,,,,,,,,,,999,
bakunin@aix_5_2:/tmp> grep "^\([^,]*,\)\{7\}9999" test.asc
x(xx,x,x,,,x,x,9999,,x,,,xx,,,xxxx,,,,,,,,,,,,,,,,,,999,
bakunin@aix_5_2:/tmp> grep "^\([^,]*,\)\{7\}8888" test.asc
x(xx,x,x,,,x,x,8888,,x,,,xx,,,xxxx,,,,,,,,,,,,,,,,,,999,
bakunin@aix_5_2:/tmp> grep "^\([^,]*,\)\{33\}999" test.asc
x(xx,x,x,,,x,x,9999,,x,,,xx,,,xxxx,,,,,,,,,,,,,,,,,,999,
x(xx,x,x,,,x,x,8888,,x,,,xx,,,xxxx,,,,,,,,,,,,,,,,,,999,
bakunin@aix_5_2:/tmp> what /usr/bin/grep
/usr/bin/grep:
        61      1.14  src/bos/usr/ccs/lib/libc/__threads_init.c, libcthrd, bos520 7/11/00 12:04:14
        46      1.72.2.3  src/bos/usr/bin/grep/grep.c, cmdscan, bos52L, l2005_19B0 4/14/05 04:52:19

I could test with other versions of AIX, but i suppose there would be no difference. Is in your data any non-printing character or something like that? have you tried the command outside of the script? Maybe its one of these "obvious" yet hard to find things one tends to think about always last.

I hope this helps.

bakunin

There are no non-printing characters and I did those tests on the command line.

I did a what /usr/bin/grep and got (typed it as no way of copy/paste):
46 1.59 src/bos/usr/bin/grep/grep.c, cmdscan, box420, 9613T 12/19/95 08:22:09