Operating System - Linux
1753261 Members
5153 Online
108792 Solutions
New Discussion

Re: Scriptng Issue: Different output on HPUX and Linux

 
dewa
Occasional Contributor

Scriptng Issue: Different output on HPUX and Linux

Hi All,

 

Please help. I have a file called file1:

# more file1
ab12
bc34
xy89
q123
gone
1234

 

When I run this command on HPUX, it gives me the output as below:

 

[root@HPUX:/var/tmp]

# cat dewa |grep -v -E "^[A-z][A-z][0-9][0-9]|^[A-z][0-9][0-9][0-9]"
gone
1234

 

However, if I run the same command on Linux, it gives me different output which is not correct.

 

[root@Linux:/var/tmp]
# cat dewa |grep -v -E "^[A-z][A-z][0-9][0-9]|^[A-z][0-9][0-9][0-9]"
ab12
bc34
xy89
q123
gone
1234

 

What is the issue? How to make the output on Linux the same as what I get on HPUX?

 

Thanks for your help.

 

Regards,

Dewa

4 REPLIES 4
James R. Ferguson
Acclaimed Contributor

Re: Scriptng Issue: Different output on HPUX and Linux

Hi:

 

First, though I adore cats we don't need to bring them into this.

 

Now, instead of:

 

# grep -v -E "^[A-z][A-z][0-9][0-9]|^[A-z][0-9][0-9][0-9]" file

 Use:

 

grep -v -E "^[A-Za-z][A-Za-z][0-9][0-9]|^[A-Za-z][0-9][0-9][0-9]" file

 ...that is well defined ranges.  I would also re-write the last to this:

 

# grep -v -E "^([A-Za-z][A-Za-z][0-9][0-9]|[A-Za-z][0-9][0-9][0-9])" file

 Regards!

 

...JRF...

James R. Ferguson
Acclaimed Contributor

Re: Scriptng Issue: Different output on HPUX and Linux

Hi (again):

 

Interestingly using a Centos 5.6 distribution I also find that this will give you the result you want:

 

# grep -v -E "^([a-Z][a-Z][0-9][0-9]|^[a-Z][0-9][0-9][0-9])" file

 Regards!

 

...JRF...

H.Merijn Brand (procura
Honored Contributor

Re: Scriptng Issue: Different output on HPUX and Linux

The default grep on HP-UX is not the GNU version:

 

$  /usr/bin/grep --version
/usr/bin/grep: illegal option -- -
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvwx] -e pattern_list...
[-f pattern_file...] [file...]
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvwx] [-e pattern_list...]
-f pattern_file... [file...]
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvwx] pattern [file...]

 If you would install the GNU version (somewhere)

$ /pro/local/bin/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.

 

Their regular expression engines do not match (at all). To add to this confusion, one can select different matching engines in GNU grep is so configured

Regexp selection and interpretation:
  -E, --extended-regexp     PATTERN is an extended regular expression
  -F, --fixed-strings       PATTERN is a set of newline-separated strings
  -G, --basic-regexp        PATTERN is a basic regular expression
  -P, --perl-regexp         PATTERN is a Perl regular expression

  Being a perl freak, you'll understand that I use -P quite often: I know that syntax, and it is portable.

 

Enjoy, Have FUN! H.Merijn
Doug O'Leary
Honored Contributor

Re: Scriptng Issue: Different output on HPUX and Linux

Hey;

 

>>First, though I adore cats we don't need to bring them into this.

 

Nicest presentation of the "Useless use of cat award" that iI've seen in ages!

 

Doug

 


------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html