我有一个文件如下
Tran No Date Vchr No Debit Credit
1239 05/06/2015 115 750.00 .00
instal A Roy Sr/Ag/Pol No : 33333
being the exp towards tour
neft ac no 00088888
1295 10/06/2015 123 400.00 .00
instal P Paul Sr/Ag/Pol No :54322
being the mobile bill payment
neft zc no 00222222
我想要的输出如下:
1239 05/06/2015 115 750.00 .00 A Roy 33333 being the exp towards tour
1295 10/06/2015 123 400.00 .00 P Paul 54322 Being the mobile payment
我可以使用 来实现结果awk
吗?
答案1
根据介绍的样本日期,很容易完成任务sed
sed -n '/^12[0-9][0-9]/{N;N;s^\n\|\s*Sr/Ag/Pol\s*No\s*:\s*\|\s\s\+^\t^gp;}' file
或者,如果您愿意,可以使用awk
:
awk '/^12/,/:/{sub("\\s*Sr/Ag/Pol No :\\s*","\t"); NF=NF; printf $0" "}/being/' OFS='\t' file