Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

gappy table

Status
Not open for further replies.

krava

Programmer
Jun 4, 2007
48
YU
Hi,

Could somebody help me to solve this problem?

I copy here part of the table (I hope it will keep the format when you receive this thread):

ESO 268-044 4a 70.0 9.0 272.3 251.8 113.1 2.2 14.5 10 2
ESO 323-042 4c 54.0 9.0 160.1 4.0
ESO 358-006 4b 48.5 3.2 155.0 25.0
ESO 358-059 4b 49.8 3.5 117.0 56.0
ESO 382-006 4a 54.0 8.0 283.8 263.0 121.3 9.2 22.0 1 3
ESO 383-002 4a 109.0 28.0 348.3 341.2 158.7 5.3 22.0 1 4
ESO 383-088 4a 70.0 14.0 339.6 332.7 147.8 4.2 22.0 1 4 1
ESO 445-015 4a 113.0 13.0 445.7 402.7 195.3 3.3 14.5 10 5 1
ESO 446-001 4a 123.0 12.0 358.9 345.1 190.8 3.2 22.0 1 4 1

As can be seen, blanko space separate columns in the table BUT there is no rule how many blankos are between. Some columns are separated with 1 some with 2 or even more blankos (this is maybe not so obvious looking the table but it is so).

I would like to fill gaps (missing data) in the table with for example NA but not touching blankos that separate columns. Do you have an easy solution for this?

thanks
k.
 
Hi

krava said:
I hope it will keep the format when you receive this thread
Then enclose it between [tt][ignore]
Code:
[/ignore][/tt] and [tt][ignore]
[/ignore][/tt] or [tt][ignore][tt][/ignore][/tt] and [tt][ignore][/tt][/ignore][/tt] TGML tags.
Code:
[blue]master #[/blue] awk -vFIELDWIDTHS='4 8 3 6 5 6 6 6 5 5 3 4 3' -vOFS= '{for(i=1;i<=NF;i++)if($i!~/[^ ]/)sub(/../,"NA",$i)}1' /input/file
ESO 268-044 4a  70.0  9.0 272.3 251.8 113.1  2.2 14.5 10   2 NA
ESO 323-042 4c  54.0  9.0 NA    NA    160.1  4.0 NA   NA NA  NA
ESO 358-006 4b  48.5  3.2 NA    NA    155.0 25.0 NA   NA NA  NA
ESO 358-059 4b  49.8  3.5 NA    NA    117.0 56.0 NA   NA NA  NA
ESO 382-006 4a  54.0  8.0 283.8 263.0 121.3  9.2 22.0  1   3 NA
ESO 383-002 4a 109.0 28.0 348.3 341.2 158.7  5.3 22.0  1   4 NA
ESO 383-088 4a  70.0 14.0 339.6 332.7 147.8  4.2 22.0  1   4 1
ESO 445-015 4a 113.0 13.0 445.7 402.7 195.3  3.3 14.5 10   5 1
ESO 446-001 4a 123.0 12.0 358.9 345.1 190.8  3.2 22.0  1   4 1
The above code is [tt]gawk[/tt] specific. Will not work with other implementations.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top