[英]No Output from grep or fgrep with -f option not working
I have the following regular expression in a file. 我在文件中具有以下正则表达式。 BTW, im on SunOS
BTW,SunOS上的即时消息
Ex: File pattern contains the following lines: 例如:文件模式包含以下几行:
Ora-[0-9]
violated
I have a file " datafile " which contain the following: 我有一个文件“ datafile ”,其中包含以下内容:
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. 现在,我想使用grep -f或fgrep -f命令查找与模式文件的正则表达式匹配的行。 The below two command didn't work when patter file contained ONLY "Ora-[0-9]" line.
当模式文件仅包含“ Ora- [0-9]”行时,以下两个命令不起作用。
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. 尝试使用
/usr/xpg4/bin/grep
不是/usr/bin/grep
,这似乎是您获得结果的地方。 There are a lot of UNIX commands in Solaris /usr/bin
that are old for retro-compatibility. Solaris
/usr/bin
中有许多UNIX命令,这些命令较旧,可以追溯兼容。 /usr/bin/awk
is notorious. /usr/bin/awk
是臭名昭著的。
You can see the grep you get by default use of the grep
command: 您可以使用
grep
命令查看默认情况下获得的grep
:
which grep
You can change this for your process by placing /usr/xpg4/bin
in your PATH variable before you come to /usr/bin. 您可以通过在进入
/usr/xpg4/bin
之前将/usr/xpg4/bin
放入PATH变量中来为您的过程进行更改。 Or use grep
as an alias for /usr/xpg4/bin/grep. 或将
grep
用作/ usr / xpg4 / bin / grep的别名。
add an alias in .profile (maybe .bashrc, whatever): 在.profile中添加一个别名(可能是.bashrc,无论如何):
alias grep=/usr/xpg4/bin/grep
change your PATH (again in .profile or wherever): 更改您的PATH(再次在.profile中或任何位置):
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. 更改PATH可能会影响现有个人脚本的行为,通常以较小但有时令人讨厌的方式。
Also consider just using egrep -i '(ora|violated)'
-- suggestion based on your example. 也可以考虑只使用
egrep -i '(ora|violated)'
-基于您的示例的建议。 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". 我认为您没有注意到该模式仅与“ Ora”匹配,但是如果您在数据文件中查找,则有一个“ ora”和一个“ ORA”,但没有“ Ora”。 Hence, either include case-insensitive matching or correct the pattern.
因此,包括不区分大小写的匹配或纠正模式。
EDIT: Apologies, bit late here. 编辑:道歉,在这里有点晚了。 I didn't notice the SunOS.
我没有注意到SunOS。 Seems that on SunOS the grep implementation differs since it runs normally on my linux box here.
似乎在SunOS上,grep实现不同,因为它可以在此处的Linux盒中正常运行。 Issue of Solaris grep?
Solaris grep问题?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.