grep -aiH '^WARN\|^ERROR\|^FATAL' myLogFile.log | \
...
我写
if (!line.startsWith("ERROR") || !line.startsWith("WARN")
|| !line.startsWith("FATAL")) {
...
但是,如何将一个兼顾 “i
” 标志,进行比较的情况下无动于衷?
grep -aiH '^WARN\|^ERROR\|^FATAL' myLogFile.log | \
...
我写
if (!line.startsWith("ERROR") || !line.startsWith("WARN")
|| !line.startsWith("FATAL")) {
...
但是,如何将一个兼顾 “i
” 标志,进行比较的情况下无动于衷?
只是转换线变成大写字母串首先,用这种方法:
http://docs.oracle.com/javase/1.3/docs/api/java/lang/String.html#toUpperCase()
所以不是!line.startsWith(...)
写!line.toUpperCase().startsWith(...)
。
可能也想看看公地郎StringUtils的:
http://commons.apache.org/lang/api/org/apache/commons/lang3/StringUtils.html
例如!StringUtils.startsWithIgnoreCase(line, "ERROR")
这具有空安全以及利益;如果line
为空,它将返回false而不是抛出NullPointerException。
终于 - 你也可以尝试类似!line.matches("(?i)(WARN|ERROR|FATAL).*")
不错,干净。谢谢 – JAM 2011-12-19 20:39:18