Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

Input Data

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 

Query

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.

Expected Output

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
                                       
                                           
        

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
150 views
Welcome To Ask or Share your Answers For Others

1 Answer

sed -e :a -e '$!N:s/
|//;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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...