一列值中的多个值在UNIX输出中打印

时间:2018-11-19 11:48:17

标签: bash shell unix

Ravi : Siva : Venki 
Siva : venki : Venkata krishna 
Reddy 
date : Number : test 

第二行第三列的值包含多行 第三列值的输出应如下所示 输出

Venki 
Venkata krishna  Reddy 
test

1 个答案:

答案 0 :(得分:0)

检查一下:

> cat broken_3rd_col.txt
Ravi : Siva : Venki 
Siva : venki : Venkata krishna 
Reddy 
date : Number : test 
> awk -F":" ' { if(NF==1) { prev=prev$1; next } if( prev !~/^$/ && NR>1 ) { print prev ;} prev=$0 } END { print prev }' broken_3rd_col.txt
Ravi : Siva : Venki 
Siva : venki : Venkata krishna Reddy 
date : Number : test 
> 
> awk -F":" ' { if(NF==1) { prev=prev$1; next } if( prev !~/^$/ && NR>1 ) { print prev ;} prev=$0 } END { print prev }' broken_3rd_col.txt | awk -F":" ' { print $3 } ' 
 Venki 
 Venkata krishna Reddy 
 test 
> 

Update1:​​

基于新输入:

$ cat date_pattern.txt
2018-11-18 03:05:17 : INFO : (571 | WRITER_1__1) : node02_p : WRT_8167 : Start loading table [DUAL] at: Sun Nov 18 03:05:16 2018
2018-11-18 03:05:17 : INFO : (571 | WRITER_1_1) : node02_p : WRT_8168 : End loading table [DUAL] at: Sun Nov 18 03:05:16 2018
2018-11-18 03:05:17 : INFO : (571 | WRITER_1*_1) : node02_p : WRT_8035 : Load complete time: Sun Nov 18 03:05:16 2018

LOAD SUMMARY
============

WRT_8036 Target: DUAL (Instance Name: [DUAL1])
WRT_8044 No data loaded for this target

2018-11-18 03:05:17 : INFO : (571 | WRITER_1_*_1) : node02_p : WRT_8168 : End loading table [DUAL] at: Sun Nov 18 03:05:16 2018

$ awk -F" " ' { if($0!~/^[0-9]{4}-[0-9]{2}/) { prev=prev$0; next } if( prev !~/^$/ && NR>1 ) { print prev ;} prev=$0 } END { print prev }' date_pattern.txt  | perl -ne
 ' { if( /(.+?) WRT(.+?):(.+)/ and $x=$3 ) { print "$x\n" } } '  > res4.txt

$

enter image description here