[英]Shell script for Grepping/retrieving value from text log file (sqlcode field value)
Hello I have the need to retrieve the sqlcode value from the outfiles that are generated after running sql statements.您好,我需要从运行 sql 语句后生成的输出文件中检索 sqlcode 值。
The following value of the sqlcode below is obviously 0 and i would need to be able to grab that value from multiple blocks of statements formatted like below.下面的 sqlcode 的以下值显然是 0,我需要能够从格式如下的多个语句块中获取该值。
I cannot use GNU functions - grep/sed/awk may work but i havent been able to grab the sqlcode value using them myself...我不能使用 GNU 函数 - grep/sed/awk 可以工作,但我无法自己使用它们获取 sqlcode 值......
Outfile will look like the following: Outfile 将如下所示:
SQLCA Information
sqlcaid : SQLCA sqlcabc: 136 sqlcode: 0 sqlerrml: 0
sqlerrmc:
sqlerrp : SQLRI01F
sqlerrd : (1) -2147221503 (2) 1 (3) 4
(4) 0 (5) 0 (6) 0
sqlwarn : (1) (2) (3) (4) (5) (6)
(7) (8) (9) (10) (11)
sqlstate: 00000
sed -n '/sqlcode: /s/.*sqlcode: \([0-9]\+\) .*/\1/p'
If the line has the string "sqlcode: ", then substitute everything and remember one or more numbers after the string "sqlcode: " and before a space and print that remembered part.如果该行包含字符串“sqlcode:”,则替换所有内容并记住字符串“sqlcode:”之后和空格之前的一个或多个数字,并打印记住的部分。
Live version available at tutorialspoint .可在tutorialspoint获得实时版本。
awk '/sqlcode/ {print $7}' file
awk '/sqlcode/ {print $7}' 文件
0 0
awk looks in the file for the default value / sqlcode / awk 在文件中查找默认值 / sqlcode /
print $ 7 prints the seventh field print $ 7 打印第七个字段
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.