Hi,
input:
what I am trying to get:
I tried to create first an UDF for printing repeats, but I think I have an issue with my END section or my array:
With this code it adds the same number of "|" no matter the number of fields the record contains:
NOTE: I am using gawk (just in case I would have missed a built-in function for printing repeats)
input:
Code:
AA|BB|CC
DD|EE
FF
Code:
AA|BB|CC
DD|EE|
FF||
Code:
function repeat(str, n, rep, i)
{
for(i=1 ;i<n;i++)
rep=rep str
return rep
}
BEGIN{FS=OFS="|"}
{
a[NR]=$0
if(NF>max){
max=NF}
}
END{
for(i in a){
if(NF<max){
x=(max-NF)
print a[i] repeat("|",x)}
else{
print a[i]}
}
}
Code:
AA|BB|CC|
DD|EE|
FF|