实际日志文件:
ERROR:
ORA-12514: TNS:listener does not currently know of service requested in connect
descriptor
xyz:5:90:34:89:22:07
abbc1:6:346:78:89:100:01
ERROR:
ORA-01033: ORACLE initialization or shutdown in progress
Process ID: 0
Session ID: 0 Serial number: 0
abbc1:6:346:78:89:100:01
SP2-0306: Invalid option.
Usage: CONN[ECT] [{logon|/|proxy} [AS {SYSDBA|SYSOPER|SYSASM}] [edition=value]]
where <logon> ::= <username>[/<password>][@<connect_identifier>]
<proxy> ::= <proxyuser>[<username>][/<password>][@<connect_identifier>]
SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus
xyz:5:90:34:89:22:07
abbc1:6:346:78:89:100:01
v-gz1:999:39:56:23:101:123
ERROR:
ORA-12514: TNS:listener does not currently know of service requested in connect
descriptor
v-gz1:999:39:56:23:101:123
所需输出:
xyz:5:90:34:89:22:07
abbc1:6:346:78:89:100:01
abbc1:6:346:78:89:100:01
xyz:5:90:34:89:22:07
abbc1:6:346:78:89:100:01
v-gz1:999:39:56:23:101:123
v-gz1:999:39:56:23:101:123
我正在寻找的,基于 coln (:) 处理日志文件
sed '/^ :*$/d' logfile1 > logfile2
(删除前面有空格的行:)sed '/^: *$/d' logfile2 > logfile3
(删除后面有空格的行:)删除没有的行
:
答案1
grep -v " " $IN | grep -P ":.*:"
答案2
看起来所有有效行都有一个冒号后跟一个十进制数字。它们还以小写字母数字字符串开头,可能包括连字符。所以你的正则表达式是
^[a-z0-9-]+[0-9]
您的输出在每个输出行之后都有一个空行。如果这就是您真正想要的,请使用 sed:
sed -Ene '/^a-z0-9-]+:[0-9]/ s/$/\n/p' filename
如果不需要双换行符,则 grep 中的相同模式会更简单。