如何找到多個字符串在文件中查找文件多重字符串,其應該返回真正當所有的字符串存在於用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。請顯示樣本數據以及預期的輸出結果以及您嘗試解決問題所做的一些努力。 –