示例(文件包含以下文字):
tom is really really cool! joe for the win!
tom is actually smart.
tom and joe are best buddies. Joe is smart.
joe works hard
现在我想在这个文件中找不到使用UNIX
在单行中使用joe和tom的行。
所以答案应该是2(即仅限第一和第四行)
答案 0 :(得分:1)
您可以使用带有grep
标志的普通-c
来计算实例。输入file
,
grep 'tom.*joe\|joe.*tom' file
tom is really really cool! joe for the win!
tom and joe are best buddies. Joe is smart.
grep -c 'tom.*joe\|joe.*tom' file
2