bash - Filling in gaps with awk or anything -


i have list such below, 1 column position , other columns aren't important question.

1  1 2 3 4 5 2  1 2 3 4 5 5  1 2 3 4 5 8  1 2 3 4 5 9  1 2 3 4 5 10 1 2 3 4 5 11 1 2 3 4 5 

i want fill in gaps such list continuous , reads

1  1 2 3 4 5 2  1 2 3 4 5 3  0 0 0 0 0 4  0 0 0 0 0  5  1 2 3 4 5 6  0 0 0 0 0  7  0 0 0 0 0  8  1 2 3 4 5 9  1 2 3 4 5 10 1 2 3 4 5 11 1 2 3 4 5 

i familiar awk , shell scripts, whatever way can done fine me. help..

this one-liner may work you:

awk '$1>++p{for(;p<$1;p++)print p"  0 0 0 0 0"}1' file 

with example:

kent$  echo '1  1 2 3 4 5 2  1 2 3 4 5 5  1 2 3 4 5 8  1 2 3 4 5 9  1 2 3 4 5 10 1 2 3 4 5 11 1 2 3 4 5'|awk '$1>++p{for(;p<$1;p++)print p"  0 0 0 0 0"}1'          1  1 2 3 4 5 2  1 2 3 4 5 3  0 0 0 0 0 4  0 0 0 0 0 5  1 2 3 4 5 6  0 0 0 0 0 7  0 0 0 0 0 8  1 2 3 4 5 9  1 2 3 4 5 10 1 2 3 4 5 11 1 2 3 4 5 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -