1

I've an egrep statement(as a part of a script) purpose of which is to check for any characters other than ASCII characters 0-9, a-z, A-Z, space, enter, newline. Also if text is enclosed in [], it can contain 0-9, a-z, A-Z, _, = which works perfectly as I expect on a RHEL box:

uname -a
Linux labeir1 2.6.18-371.el5 #1 SMP Thu Sep 5 21:21:44 EDT 2013 x86_64 x86_64 x86_64 GNU/Linux
cat /etc/redhat\-release
Red Hat Enterprise Linux Server release 5.10 (Tikanga)

The egrep statement:

egrep -v "^[ ]*([a-zA-Z0-9\t\n\v\f\r ]*|\[{1}[_a-zA-Z0-9\t\n\v\f\r ]*(=[a-zA-Z0-9\t\n\v\f\r ]*)?\]{1})[ ]*$" file1

File1:

[FEATURE_ID=2]
[FEATURE_REV=1]
[NO_OF_BYTES=18]
001203658080400160b9d0ae45000080
[CRC]
c068

Output:

Nothing, as the patterns of file1 matches

But when I use this on a SunOS system, it fails to behave the same way:

uname -a
SunOS prodOTA1 5.9 Generic_118558-38 sun4us sparc FJSV,GPUZC-M

Output on SUNOS:

[FEATURE_ID=2]
[FEATURE_REV=1]
[NO_OF_BYTES=18]
[CRC]

Can you please help to use the exact equivalent of egrep -v "^[ ]*([a-zA-Z0-9\t\n\v\f\r ]*|\[{1}[_a-zA-Z0-9\t\n\v\f\r ]*(=[a-zA-Z0-9\t\n\v\f\r ]*)?\]{1})[ ]*$" in SunOS, so that I get the exact output as in RHEL box.

dig_123
  • 2,240
  • 6
  • 35
  • 59
  • 2
    I don't know but you can start to remove these useless `{1}`. – Casimir et Hippolyte Apr 29 '16 at 19:33
  • the regex you're using, and the requirements you list, do not match, not even in intent. – Scott Weaver Apr 29 '16 at 19:45
  • about the group: Indeed I didn't see it (but refresh the page, this part of my comment no longer exists). About `{1}`: It is totally useless, it doesn't ensure anything, remove it, never write it again. – Casimir et Hippolyte Apr 29 '16 at 19:45
  • @CasimiretHippolyte Its grouped under `()` . Also I'm using the `{1}` because I want to make sure patterns like `[[[text=text]`, `text=text]` should not match. Only pattern like `[text_text=text]`, `[text=text]`, `[text]` or `text` should match. where by `text` I mean `0-9,a-z,A-Z,space,newline,tab,enter` – dig_123 Apr 29 '16 at 19:47
  • @sweaver2112 Here is what I want to achieve : Only pattern like `[text_text=text]`, `[text=text]`, `[text]` or `text` should match. where by `text` I mean `0-9,a-z,A-Z,space,newline,tab,enter`. Anything other than this will not match i.e `egrep -v` should show it. How can I achieve this in SunOS – dig_123 Apr 29 '16 at 19:50
  • No it shouldn't because the `-v` parameter inverts the result. – Casimir et Hippolyte Apr 29 '16 at 19:51
  • I want to make sure patterns like `[[[text_text=text]`, `text_text=text]` , `[[[text=text]` `text=text] `[text=text` should not match as well – dig_123 Apr 29 '16 at 19:52
  • unix.stackexchange.com may be a better place for this question. – Barmar Apr 29 '16 at 19:53
  • Try to unescape the closing square bracket, remove the `{1}`s, remove `\n\v\f\r` from the character classes. – Casimir et Hippolyte Apr 29 '16 at 19:55

0 Answers0