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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

filling gaps 1

Status
Not open for further replies.

Kfed69

Technical User
Jan 4, 2010
1
AU
Hi,

I have a file which consists of two columns, for example

1 4.00
2 5.25
6 8.12


What I want to do is fill in the gaps between integers in column 1 and insert 0.00 in column 2 for each "missing integer" so the output I want is:

1 4.00
2 5.25
3 0.00
4 0.00
5 0.00
6 8.12

I've tried a variety of while and if loops and can't get what i want.

Any help greatly appreciated.

Cheers,

Kfed69
 
Hi

Kfed69 said:
I've tried a variety of while and if loops and can't get what i want.
Next time we will wait until you post some of those "variety of while and if loops" you tried.
Code:
[b]set[/b] fil [teal][[/teal][b]open[/b] [green][i]"Kfed69.txt"[/i][/green] r[teal]][/teal]

[b]set[/b] prev [purple]0[/purple]
[b]while[/b] [teal]{[/teal][teal]![[/teal][b]eof[/b] [navy]$fil[/navy][teal]][/teal][teal]}[/teal] [teal]{[/teal]
  [b]set[/b] line [teal][[/teal][b]gets[/b] [navy]$fil[/navy][teal]][/teal]
  [b]set[/b] part [teal][[/teal][b]split[/b] [navy]$line[/navy][teal]][/teal]
  [b]set[/b] nr [teal][[/teal][b]lindex[/b] [navy]$line[/navy] [purple]0[/purple][teal]][/teal]
  [b]for[/b] [teal]{[/teal][b]set[/b] i [teal][[/teal][b]expr[/b] [navy]$prev[/navy][teal]+[/teal][purple]1[/purple][teal]][/teal][teal]}[/teal] [teal]{[/teal][navy]$i[/navy][teal]<[/teal][navy]$nr[/navy][teal]}[/teal] [teal]{[/teal][b]incr[/b] i[teal]}[/teal] [teal]{[/teal]
    [b]puts[/b] [green][i]"$i 0.00"[/i][/green]
  [teal]}[/teal]
  [b]set[/b] prev [navy]$nr[/navy]
  [b]puts[/b] [navy]$line[/navy]
[teal]}[/teal]

[b]close[/b] [navy]$fil[/navy]

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top