Is there any option of the grep command to suppress the effect of empty lines in the pattern file? I would prefer this option than always checking and filtering the nascent pattern file.
Here is an example (in pattern_file
, there is an empty line):
$ cat pattern_file
APPLE
PEAR
$ cat file
Nothing
fruit
$ grep -f pattern_file file
Nothing
fruit
要忽略病毒码文件中的空行:
grep -f <(grep . pattern_file) file
grep -v '^$'
This actually grabs all the lines except for newlines. You can pipe the result to your grep like this: grep -v '^$'| otherGrep
grep -v '^$'| otherGrep
About -f
option:
A null pattern can be specified by an empty line in pattern_file .
So, it is a feature, and you should delete empty lines , eg with sed
:
sed '/^$/d' | grep -f ...
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.