I have a series of field-delimited files (symbol | ) with varying column widths:
File 1:
2p | 2P* | 1/2 | 2 | 10.19880615024 |
2s | 2S | 1/2 | 2 | 10.19881052514816 |
2 | | | 8 | 10.1988358 |
2p | 2P* | 3/2 | 4 | 10.19885151459 |
3p | 2P* | 1/2 | 2 | 12.0874936591 |
3s | 2S | 1/2 | 2 | 12.0874949611 |
3 | | | 18 | 12.0875052 |
3d | 2D | 3/2 | 4 | 12.0875070783 |
File 2:
2s2.2p3 | 4S* | 3/2 | 4 | 0.0000000 |
2s2.2p3 | 2D* | 5/2 | 6 | 2.3835298 |
2s2.2p3 | | 3/2 | 4 | 2.3846100 |
2s2.2p3 | 2P* | 1/2 | 2 | 3.5755704 |
2s2.2p3 | | 3/2 | 4 | 3.5756182 |
2s2.2p2.(3P).3s | 4P | 1/2 | 2 | 10.3259087 |
2s2.2p2.(3P).3s | | 3/2 | 4 | 10.3300944 |
2s2.2p2.(3P).3s | | 5/2 | 6 | 10.3358956 |
2s2.2p2.(3P).3s | 2P | 1/2 | 2 | 10.6796703 |
2s2.2p2.(3P).3s | | 3/2 | 4 | 10.6899808 |
and I would like to fill the blanks in the second column with the corresponding values in the last non-NULL column above: Example for file 2:
2s2.2p3 | 4S* | 3/2 | 4 | 0.0000000 |
2s2.2p3 | 2D* | 5/2 | 6 | 2.3835298 |
2s2.2p3 | 2D* | 3/2 | 4 | 2.3846100 |
2s2.2p3 | 2P* | 1/2 | 2 | 3.5755704 |
2s2.2p3 | 2P* | 3/2 | 4 | 3.5756182 |
2s2.2p2.(3P).3s | 4P | 1/2 | 2 | 10.3259087 |
2s2.2p2.(3P).3s | 4P | 3/2 | 4 | 10.3300944 |
2s2.2p2.(3P).3s | 4P | 5/2 | 6 | 10.3358956 |
2s2.2p2.(3P).3s | 2P | 1/2 | 2 | 10.6796703 |
2s2.2p2.(3P).3s | 2P | 3/2 | 4 | 10.6899808 |
This question is similar to the one in here where I can do this in the first column using awk through the command:
awk -F"|" '/^ /{$0=(x)substr($0,length(x)+1)}{x=$1}1' "$file"
however I am not knowleadgeable enough to make it work in the second column (or any arbitrary colum for that matter).
Can someone help? Thanks in advance!