-2

我想删除基于“CLIENT TOTAL”的行和随后的单元行,直到下一个名称。
在“CLIENT TOTAL”行之后的单元行数(即 30.0 和 15.0 行)可能会有所不同,直到下一个名称。最重要的是文件没有分隔。下面给出的是我的输入文件。输入:

RELATIVITY/OF 32629 DT MBSA
HALL 15.0 5,850 HALL 30.0 21,650 RELATIVITY/OF 34145 DT MBSA
HALL 30.0 10,850 *CLIENT TOTAL RELATIVITY/OF 38,350 30.0 32,500 15.0 5,850 PFIZER 96607 DT MBSA
HALL 15.0 32,700 HALL 30.0 21,300 PFIZER 96609 DT MBSA
HALL 60.0 30,200 HALL 75.0 182,100 HALL 90.0 67,700 *客户总数 PFIZER 334,000 90.0 67,700 30.0 21,300 15.0 32,700

我想要我的输出如下。
输出:

相对论/32629 DT MBSA
HALL 15.0 5,850 HALL 30.0 21,650相对论/34145 DT MBSA
Hall 30.0 10,850 Pfizer 96607 DT MBSA Hall
15.0 32,700 32,700 HALL 30.0 HALL 30.0 21,300 PFISE 96609 DT MBSA
60.0,70,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,000,0.0,000,0.0,0,0,0,0led 30.0,0.0,0,0,0,0,0,0,0m

4

2 回答 2

1

Through awk,

$ awk '$1=="-----"{x=0} NF==1{x=1}x' file
34567
20.0    5,678
20.0    5,678
20.0    5,678
20.0    5,678
20.0    5,678
78545
20.0    41,424
20.0    41,424
30.0    41,424

It skips the lines which contains ----- in the column 1 upto the line in which the whole line$0 is equivalent to column 1 $1.

Update:

$ awk 'NF==1{print; var=$1}NF==2{print var"   "$2}' file
34567
34567   5,678
34567   5,678
34567   5,678
34567   5,678
34567   5,678
78545
78545   41,424
78545   41,424
78545   41,424
于 2014-07-05T13:52:13.577 回答
0
$ cat tst.awk
BEGIN{ FS=OFS="\t" }
/^[[:digit:]]+[[:space:]]*$/ { id = $1; inRec = 1 }
/^-/  { inRec = 0 }
inRec { print id, $2 }

.

$ awk -f tst.awk file
25333
98275
98275   68,000
98275   149,000
98275   41,000
98275
98275   22,000
98275   162,000
25333
31932
31932   334,000
31932
31932   53,000
31932   47,000
于 2014-07-07T15:57:14.170 回答