AIX 4.2 Korn shell and grep question


 
Thread Tools Search this Thread
Operating Systems AIX AIX 4.2 Korn shell and grep question
# 1  
Old 11-04-2008
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 ...
# 2  
Old 11-04-2008
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"...

Code:
grep 'a*bc' somefile

would match bc, abc, aabc, aaabc, aaaabc, etc...
# 3  
Old 11-04-2008
try
Code:
print ${.sh.version}

or

Code:
what /bin/ksh | grep Version

# 4  
Old 11-05-2008
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
# 5  
Old 11-06-2008
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.

Last edited by Browser_ice; 11-06-2008 at 11:22 AM..
# 6  
Old 11-06-2008
Quote:
Originally Posted by Browser_ice
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 ?
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:

Code:
[^,]*,

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:

Code:
\([^,]*,\)\{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
# 7  
Old 11-06-2008
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help when using Typeset in AIX Korn Shell

Guys, please help! I am currently using an AIX server however whenever I tried to use the typeset -F3, the variable is resulting with a "#". In the given example below, I declared x to be a decimal holding 3 decimal places = 1.455. However whenever I tried to echo the $x, the resulting value... (9 Replies)
Discussion started by: zzavilz
9 Replies

2. Shell Programming and Scripting

Korn shell behaviour in AIX

Hi, Consider the code snippet below: fun() { while read x do echo $x done < somefile_that_does_not_exists } fun echo I am here Korn shell on HPUX prints the message "I am here", while the behaviour is different on AIX korn shell. We do not get the message on AIX. Any... (5 Replies)
Discussion started by: 116@434
5 Replies

3. UNIX for Dummies Questions & Answers

List of 'if -f' options - AIX / Korn Shell

Hi all, Can someone point me in the right direction for a manual on the various statement options for 'if'. Basically I have a piece of code which says: if ] and I wondered what the -f was. I know the '!' means not equal.. As usual any help much appreciated.. (5 Replies)
Discussion started by: Grueben
5 Replies

4. Shell Programming and Scripting

Korn Shell programming (FTP, LOOPS, GREP)

Hello All, I have another Korn shell question. I am writing a script that will ftp a file from my production database to my test database. To this, I have to construct a loop that checks a specified folder for a file. If the file exists, I want it execute the ftp protocol and then exit. ... (2 Replies)
Discussion started by: jonesdk5
2 Replies

5. Shell Programming and Scripting

AIX Korn shell sed -s problem

In a Korn shell script I have, cat ../header | sed -e 's/flag1/$cnumb/g' > header.txt The header is short {{Company flag1}} But the result in header.txt is {{Company $cnumb}} The value of $cnumb is 120. I am trying to get the value of $cnumb into the header. I have tried /'$cnumb'/g,... (10 Replies)
Discussion started by: jcarrott
10 Replies

6. Shell Programming and Scripting

Korn shell and awk question

I am modifying a Korn shell script in using the Exceed (Solaris 10 environment). My task is to read in a .txt file with dates arranged like this (01-Sep-2006). I am to read each line and take the dates, compare them to a benchmark date and depending on if it is older than the date or the date and... (6 Replies)
Discussion started by: mastachef
6 Replies

7. Shell Programming and Scripting

korn shell question

Hi all, I am trying to tweak my ksh , i am running V: Version M-11/16/88i I have my Backspace and up/down arrows working using the following code in my ~/.profile file. set -o emacs alias __A=$(print '\020' ) alias __B=$(print '\016' ) alias __C=$(print '\006' ) alias __D=$(print... (4 Replies)
Discussion started by: mich_elle
4 Replies

8. Shell Programming and Scripting

Korn Shell Loop question

I'm needing help with assigning variables inside a while loop of ksh script. I have an input text file and ksh script below and I'm trying to create a script which will read the input file line by line, assign first and second word to variables and process the variables according to the contents. ... (4 Replies)
Discussion started by: stevefox
4 Replies

9. Shell Programming and Scripting

AWK question in the KORN shell

Hi, I have two files with the following content: gmrd.txt 235649;03;2563;598 291802;00;2563;598 314634;00;235649;598 235649;03;2563;598 393692;00;2563;598 411805;00;2563;598 411805;00;2563;598 235649;03;2563;598 414037;00;2563;598 575200;00;2563;598 70710;00;2563;598... (11 Replies)
Discussion started by: penfold
11 Replies

10. Shell Programming and Scripting

Question about Korn Shell

In Korn Shell, can you use "go to" statements? Would you then put paragraph names with a colon? For example, would you specify "goto para1" and then have the paragraph with the label para1:? I am getting an error message when Idid this. I have my paragraph name 'clsbooks:' and I get... (13 Replies)
Discussion started by: Latha Nair
13 Replies
Login or Register to Ask a Question