小编Mre*_*yes的帖子

如何将带有grep命令的字符串搜索放入if语句中?

我想在两个文件中搜索多个字符串。如果在两个文件中都找到一个字符串,则做一些事情。如果只在一个文件中找到一个字符串,那么做另一件事。

我的命令是下一个:

####This is for the affirmative sentence in both files
if grep -qw "$users" "$file1" && grep -qw "$users" "$file2"; then

####This is for the affirmative sentence in only one file, and negative for the other one
if grep -qw "$users" "$file1" ! grep -qw "$users" "$file2"; then
Run Code Online (Sandbox Code Playgroud)

否定和肯定这些陈述的方式是否正确?pd 我正在使用 KSH 外壳。

先感谢您。

grep ksh awk text-processing

11
推荐指数
3
解决办法
2295
查看次数

标签 统计

awk ×1

grep ×1

ksh ×1

text-processing ×1