我在Unix中有一个文件,包含以下内容。
{
BTEQ 13.10.00.06 Mon Jun 3 03:01:13 2013
+---------+---------+---------+---------+---------+---------+---------+----
logon TDDEV/TVDW_APP,
*** Logon successfully completed.
*** Teradata Database Release is 13.00.01.06
*** Teradata Database Version is 13.00.01.06
*** Transaction Semantics are BTET.
*** Session Character Set Name is 'ASCII'.
*** Total elapsed time was 1 second.
+---------+---------+---------+---------+---------+---------+---------+----
call TVDW_APP.PROC_OPO_GET_MAX_BATCH_ID(V_MAX_BATCH_ID);
*** Procedure has been executed.
*** Total elapsed time was 1 second.
V_MAX_BATCH_ID
--------------
9
+---------+---------+---------+---------+---------+---------+---------+----
*** BTEQ exiting due to EOF on stdin.
*** Exiting BTEQ...
*** RC (return code) = 0
}
我想从此文件中提取数字“9”并将其分配给变量。 我该怎么做呢?请帮助。 (我正在为此目的写一个ksh文件;数字9在第22行,字符11到14)
答案 0 :(得分:1)
sed "1,/^V_MAX_BATCH_ID/d" < input.txt | sed -n "/^\s*[0-9]\s*$/p" | sed "s/\s//g")
V_MAX_BATCH_ID
。答案 1 :(得分:1)
如果您知道该号码位于第23行,则可以使用单个sed
,如下所示:
$ foo=$(sed -n '23s/^ *//p' file)
$ echo "$foo"
9
或者,您可以查找V_MAX_BATCH_ID
并使用单个sed
选择其下方的第二行,如下所示:
$ foo=$(sed -n '/^V_MAX_BATCH_ID/{n;n;s/ *//p}' file)
$ echo "$foo"
9
答案 2 :(得分:0)
awk '/^V_MAX_BATCH_ID$/{getline;getline;gsub(/ /,"");print}' your_file