AIX 4.2 Korn shell and grep question


 
Thread Tools Search this Thread
Operating Systems AIX AIX 4.2 Korn shell and grep question
# 8  
Old 11-06-2008
Quote:
Originally Posted by Browser_ice
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 [^,]* ?
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 "ab*c" would be matched not only by "abc" and "abbbc" but also by "ac". It would not be matched by "adc" though.

Quote:
Originally Posted by Browser_ice
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.
hm, that is quite astonishing. I tried exactly your data and command and it is working (here on cygwin, but that shouldn't matter):

Code:
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

Last edited by bakunin; 11-06-2008 at 05:27 PM..
# 9  
Old 11-06-2008
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.
# 10  
Old 11-06-2008
Quote:
Originally Posted by bakunin
[...]command and it is working (here on cygwin, but that shouldn't matter)[...]
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.
[/code]

[... ]
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 Smilie
# 11  
Old 11-07-2008
Ok, i retried it on AIX - same result as in Cygwin:

Code:
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
# 12  
Old 11-10-2008
Quote:
Originally Posted by bakunin
Ok, i retried it on AIX - same result as in Cygwin:

Code:
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
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