如何找到多个字符串在文件中查找文件多重字符串,其应该返回真正当所有的字符串存在于用grep Linux的文件。用grep
Q
用grep
1
A
回答
0
2
要在文件中搜索多字符串,您可以在Linux上使用egrep或grep。
egrep -ri --color 'string1|string2|string3' /path/to/file
-r search recursively
-i ignore case
--color - displays the search matches with color
你可以这样做,echo $?这将显示0(真),如果你的grep匹配任何东西,1(假)如果grep命令的火柴
$? is a variable holding the return value of the last command you ran.
从这里你可以使用bash播放和创建一个小脚本或任何你需要的。
0
一个在AWK。首先,测试文件:
$ cat file
foo
bar
baz
代码和测试运行:
$ awk '
BEGIN {
RS="\177" # set something unusual to RS and append
FS=FS "\n" } # \n to FS to make the whole file one record
{
print (/foo/&&/bar/?"true":"false") } # search and output true or false
# exit (/foo/&&/bar/?0:1) # exit if you are interested in return value
' file
true
一行代码:
$ awk 'BEGIN{RS="\177";FS=FS "\n"} {print (/foo/&&/bar/?"true":"false")}' file
相关问题
- 1. 用grep
- 2. 用grep
- 3. 用grep
- 4. 用grep
- 5. 用grep
- 6. 使用BSD grep捕获stdout(可能)grep
- 7. 使用grep
- 8. 用grep匹配
- 9. 发现用grep
- 10. 使用grep -v
- 11. 用grep到
- 12. 使用grep
- 13. 使用grep
- 14. 使用grep -v
- 15. 我想用grep
- 16. 用grep文件
- 17. 使用grep
- 18. 使用grep
- 19. 用grep单数
- 20. UNIX grep命令(grep的-v grep的)
- 21. num ='ps -ef | grep -v grep | grep BatchName | wc -l'
- 22. 用grep VS使用==
- 23. +不适用于grep
- 24. 查找使用grep
- 25. grep的字用perl
- 26. 用grep或相似
- 27. 递归使用grep
- 28. Grep:如何使用?
- 29. 使用GREP和Inotifywait
- 30. Grep使用帮助
欢迎#1。请显示样本数据以及预期的输出结果以及您尝试解决问题所做的一些努力。 –