我正在尝试在日志文件中grep特定文本,但是我无法获得我感兴趣的特定文本
echo "[27 May 2019 23:42:32,418] [Accept-Nsh-Proxy-Thread] [ERROR] [::] [Appserver] Too many open files (Accept failed)" >> sl3737474646464-config_console.log | tail -f sl3737474646464-config_console.log
cat sl3737474646464-config_console.log | grep -i "\[Appserver\] Too many open files \(Accept failed\)"
但无法获取字符串
如何获得我回显的文字?
答案 0 :(得分:0)
grep
将\(
作为捕获组的开始。只需将\
和(
中的)
放下即可。
$ echo "[27 May 2019 23:42:32,418] [Accept-Nsh-Proxy-Thread] [ERROR] [::] [Appserver] Too many open files (Accept failed)" | grep -i "\[Appserver\] Too many open files (Accept failed)"
[27 May 2019 23:42:32,418] [Accept-Nsh-Proxy-Thread] [ERROR] [::] [Appserver] Too many open files (Accept failed)
或使用grep -F
开关。这会使grep从字面上解析该参数,因此您可以忘记转义:
$ echo "[27 May 2019 23:42:32,418] [Accept-Nsh-Proxy-Thread] [ERROR] [::] [Appserver] Too many open files (Accept failed)" | grep -i -F "[Appserver] Too many open files (Accept failed)"
[27 May 2019 23:42:32,418] [Accept-Nsh-Proxy-Thread] [ERROR] [::] [Appserver] Too many open files (Accept failed)