I have the following regular expression in a file. BTW, im on SunOS
Ex: File pattern contains the following lines:
Ora-[0-9]
violated
I have a file " datafile " which contain the following:
0:/scm/123451/test1.sql:dbuser@database:databasedb:no:yes:ORA-1234|key violated
1:/scm/123451/test1.sql:dbuser@database:databasedb:no:yes:ORA-|key violated
2:/scm/123451/test1_A.sql:dbuser@database:databasedb:no:yes:ORA-|key violated
3:/scm/123451/test1_B.sql:dbuser@database:databasedb:yes:yes:Violated
4.giga:key violated unique:giga
5.fifa:ora-error null value found:giga
Now, I want to use a command either grep -f or fgrep -f to find out the lines which match pattern file's regular expression. The below two command didn't work when patter file contained ONLY "Ora-[0-9]" line.
grep -if ./pattern ./datafile
frep -if ./pattern ./datafile
Am i missing something, does the pattern in the pattern file needs to be fixed strings?
Try /usr/xpg4/bin/grep
NOT /usr/bin/grep
which is what you seem to get the results for. There are a lot of UNIX commands in Solaris /usr/bin
that are old for retro-compatibility. /usr/bin/awk
is notorious.
You can see the grep you get by default use of the grep
command:
which grep
You can change this for your process by placing /usr/xpg4/bin
in your PATH variable before you come to /usr/bin. Or use grep
as an alias for /usr/xpg4/bin/grep.
add an alias in .profile (maybe .bashrc, whatever):
alias grep=/usr/xpg4/bin/grep
change your PATH (again in .profile or wherever):
Example old PATH --
PATH=/usr/bin:/usr/sbin
Example changed PATH
PATH=/usr/bin/xpg4/bin:/usr/bin:/usr/sbin
Changing your PATH can affect how your existing personal scripts behave, usually in minor but sometimes annoying ways.
Also consider just using egrep -i '(ora|violated)'
-- suggestion based on your example. This does not require a file of patterns. It can be as many alternations as you need.
I think you didn't notice that the pattern matches only "Ora" but if you look in your datafile you have a "ora" and a "ORA" but not "Ora". Hence, either include case-insensitive matching or correct the pattern.
EDIT: Apologies, bit late here. I didn't notice the SunOS. Seems that on SunOS the grep implementation differs since it runs normally on my linux box here. Issue of Solaris grep?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.