没有来自grep或fgrep的输出,-f选项不起作用

时间:2022-05-29 14:07:05

I have the following regular expression in a file. BTW, im on SunOS

我在文件中有以下正则表达式。顺便说一句,我在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. The below two command didn't work when patter file contained ONLY "Ora-[0-9]" line.

现在,我想使用命令grep -f或fgrep -f找出与模式文件的正则表达式匹配的行。当模式文件仅包含“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?

我错过了什么,模式文件中的模式是否需要修复字符串?

2 个解决方案

#1


2  

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.

试试/ usr / xpg4 / bin / grep NOT / usr / bin / grep这是你似乎得到的结果。 Solaris / usr / bin中有许多UNIX命令,这些命令对于复古兼容性而言是旧的。 / 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. Or use grep as an alias for /usr/xpg4/bin/grep.

您可以在进入/ usr / bin之前将/ usr / xpg4 / bin放入PATH变量中来更改此过程。或者使用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

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. This does not require a file of patterns. It can be as many alternations as you need.

还要考虑使用egrep -i'(ora | violated)' - 基于你的例子的建议。这不需要模式文件。它可以根据您的需要进行多次更改。

#2


1  

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.

我想你没注意到模式只匹配“Ora”,但如果你查看你的数据文件,你有一个“ora”和一个“ORA”而不是“Ora”。因此,要么包括不区分大小写的匹配,要么纠正模式。

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?

编辑:道歉,在这里迟到了。我没注意到SunOS。似乎在SunOS上grep实现不同,因为它在我的linux机箱上正常运行。 Solaris grep的问题?

#1


2  

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.

试试/ usr / xpg4 / bin / grep NOT / usr / bin / grep这是你似乎得到的结果。 Solaris / usr / bin中有许多UNIX命令,这些命令对于复古兼容性而言是旧的。 / 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. Or use grep as an alias for /usr/xpg4/bin/grep.

您可以在进入/ usr / bin之前将/ usr / xpg4 / bin放入PATH变量中来更改此过程。或者使用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

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. This does not require a file of patterns. It can be as many alternations as you need.

还要考虑使用egrep -i'(ora | violated)' - 基于你的例子的建议。这不需要模式文件。它可以根据您的需要进行多次更改。

#2


1  

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.

我想你没注意到模式只匹配“Ora”,但如果你查看你的数据文件,你有一个“ora”和一个“ORA”而不是“Ora”。因此,要么包括不区分大小写的匹配,要么纠正模式。

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?

编辑:道歉,在这里迟到了。我没注意到SunOS。似乎在SunOS上grep实现不同,因为它在我的linux机箱上正常运行。 Solaris grep的问题?