Multiple records based on :

Hi ,

I have the below source

source data
1|2|3|:123:abc|4
1|2|a| | 5
1|2|3|4|:a:s:D.....:n|t
Target data should be

1|2|3|:123:abc|4
1|2|3|:123:abc|4
1|2|a| | 5
1|2|3|4|:a:s:D.....:n|t
1|2|3|4|:a:s:D.....:n|t
1|2|3|4|:a:s:D.....:n|t
1|2|3|4|:a:s:D.....:n|t

based on the 5th column : I should print the same record..so I i have 2 :'s i have to print the record two times..if I have 5 :'s I have to print it 5 times so on

I got the below code from this forum

awk -F"|" '{s=gsub(":",":",$6); for(i=1;i<=s+1;i++) print $0}' OFS="|"  input_file

The code is splitting the records based on : , but it is removing all the rows with non :..I need to include those rows as well.

can any one tweak this code to include all the rows plus creating multiple records based on :

--Mora

1|2|3|:123:abc|4

The fifth column is "4" and where does it have ":" in it?? why it's appeared twice in output?

It will help all , if you post the proper input data.

How ever , below code should work for you.

 
awk -F"|" '{s=gsub(":",":",$5); if(s==0) { print $0;next} for(i=1;i<=s;i++) print $0}' OFS="|" input_file
awk '{a=gsub(":",":")?gsub(":",":"):1;for(i=1;i<=a;i++) print $0}' file

Try this,

awk -F":" '{if(NF==1){print;next}for(i=1;i<NF;i++){print $0}}' infile