Hii experts i have a single column of file having many blocks and the blocks are separated by > symbol.I want to resize all blocks to the same length by repeating the last number of the corresponding block.My file is given below:
file.txt
>
2.0
2.0
2.0
2.0
>
1.2
1.2
>
2.4
2.4
2.4
and my expected output is given below
>
2.0
2.0
2.0
2.0
>
1.2
1.2
1.2
1.2
>
2.4
2.4
2.4
2.4
my code is
#!/bin/sh
awk '$0==">" {
if (c && c>max)
max = c
++n
c = 0
next
}
{
r[n][++c] = $0
}
END {
for (i=1; i<=n; ++i) {
print ">"
for (j=1; j<=(max>c?max:c); ++j)
print (r[i][j] == "" ? "0.0" : r[i][j])
}
}' file
i copied the above code from github page, but it appends 0 instead of repeating last number.I hope some expert will help me. Thanks.