我有一个输出如下的文件
Sending showtrans string ...
Oldest redo log files necessary to restart Extract are:
Redo Thread 1, Redo Log Sequence Number 29334, SCN 3364.4078507030 (14452348490774), RBA 673593872
Redo Thread 2, Redo Log Sequence Number 12371, SCN 3365.484854852 (14453049805892), RBA 3443216
XID Items Extract Redo Thread Start Time SCN Redo Seq Redo RBA Status
-----------------------------------------------------------------------------------------------------------------------------------------------
75.2.549177 0 sting1 1 2015-12-23:07:26:47 3364.4078507030 (14452348490774) 29334 673593872 Running
126.6.3078970 sting2 1 2015-12-24:00:22:11 3365.308496723 (14452873447763) 29364 6462055952 Running
我需要输出为:
75.2 sting1
126.6 sting2
答案1
这应该有效:
awk '{split($1,a,".");if(a[1]!="") if(a[1]+0==a[1]){printf "%d.%d %s\n", a[1], a[2], ($2+0==$2)?$3:$2}}' input.txt
这将检查第二列何时丢失,以便获得适当的列。
答案2
您可以将多个空格视为字段分隔符,并将单个空格视为数据的一部分:
awk -F' +|[.]' '$1~"^[0-9]+"{print $1"."$2,$4}' file
输出:
75.2 sting1
126.6 sting2
答案3
我知道不是awk
- 但你已经有了awk
答案,所以我提供了另一种方法。
我可能会这样做:
perl -lne 'print "$1 $2" if m/^(\d+\.\d+)[^a-z]*(\w+)/' long_trans.txt
我们应用模式匹配,如果匹配,我们打印它捕获的内容:
^ # start of line
(\d+\.\d+) # digits seperated by a literal . (capturing)
[^a-z] # anything that isn't [a-z]
(\w+) # word characters (alphanumerics mostly) (capturing)