UNIX 添加到连续空记录的列 [英] UNIX Addition to Column to consecutive Null Record

查看:31
本文介绍了UNIX 添加到连续空记录的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的要求是将带有后续列的记录作为附加列添加到上一个记录中

The following requirement is to add the record with Subsequent columns to the previous Record as an additional Column

输入数据

1|AB|1|20||PAR 1234|||1
1|AB|1|20||PAR 1234|||1
||||SIR 234|||1
1|AB|1|20||PAR 456|||2
1|AB|1|20||PAR 233|||2
||||SIR 236|||1        
1|AB|1|20||PAR 123|||2
||||SIR 236|||1 
||||IL 236|||1 

查询

根据下面的输出;我们需要在之前的 Record 中添加 SIR 234 作为最后一列并删除下一行,就像 SIR 236 和文件的最后一行一样,想要使用 Awk 但不知道如何使用.

As per the output below; we need to add SIR 234 in the previous Record as a last column and delete the next line, like wise for SIR 236 and to the last of the file, Wanted to use Awk but not getting how.

预期输出

1|AB|1|20||PAR 1234|||1
1|AB|1|20||PAR 1234|||1|SIR 234
1|AB|1|20||PAR 456|||2
1|AB|1|20||PAR 233|||2|SIR 236   
1|AB|1|20||PAR 123|||2|SIR 111|IL 236
                                       
                                           
        

不确定如何在这种情况下尝试 AWK我尝试了非常基本的,但给出了一个错误,awk -F, '{print >$6".txt"}'文件

Not to sure how to Try AWK in this scenario I tried the very basic ones but is giving an error, awk -F, '{print > $6".txt"}' file

推荐答案

sed -e :a -e '$!N:s/\n|//;ta' -e 'P;D' File Name > File B
Awk -F'|' '{$6=$$7 $7;NF=24}1' OFS='|' File B

使用上面的语句删除多余的列并将值添加到正确的位置

Use the above statement to delete extra columns and add the value to the right place

这篇关于UNIX 添加到连续空记录的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆