Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我已经有一个日志说 file.txt。
我想检查 Bash,如果日志中存在字符串(July),如果存在,请检查日志中剩余的行是否有另一个字符串(foobar)。
如果您有可用的 awk,则 awk oneliner 可以为您完成:
awk '/July/{f=1} f&&/foobar/{print "Found foobar after July!";exit}' file
如果 noJuly或 no foobar after July,该命令不打印任何内容。当然你可以做一个 if-else,让它打印“未找到”或其他东西。
July
foobar after July