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!

tcl help 3

Status
Not open for further replies.

daisy4u721

Programmer
Aug 24, 2009
34
US
ok..... i have a file containing a list of product names..... and im trying to write a tcl code to has to seperate the list in different categories and open it in a new file.
for example i have a file containing this:
1156xx
2278xx
3342xx
2269xx
1125xx
3345xx
and im trying to write a code to put the list in this way in a new file.
The ones The twos The threes
1156xx 2278xx 3342xx
1125xx 2269xx 3345xx

some thing like this, im totally new to tcl..... any ideas or help please.

I think i would have to use a for loop but im not sure.
 
I meant your solution, how you divided the data into columns and how you created the universal columns headers.
 
Hi

Yes, I understood what you meant.

By the way, this is what I mentioned earlier :
Code:
array [b]set[/b] title [teal]{[/teal]
  [green][i]"1187"[/i][/green] [green][i]"One"[/i][/green]
  [green][i]"1148"[/i][/green] [green][i]"Other"[/i][/green]
  [green][i]"2009"[/i][/green] [green][i]"Another"[/i][/green]
[teal]}[/teal]

[b]set[/b] x [teal]{{}}[/teal]
array [b]set[/b] y [teal]{}[/teal]

[b]set[/b] infile [teal][[/teal][b]open[/b] [green][i]"list2b.txt"[/i][/green] r[teal]][/teal]
[b]set[/b] outfile [teal][[/teal][b]open[/b] [green][i]"listforprac.slk"[/i][/green] w[teal]][/teal]

[b]puts[/b] [navy]$outfile[/navy] [green][i]"ID;PSCALC3"[/i][/green]

[b]while[/b] [teal]{[/teal][teal]![[/teal][b]eof[/b] [navy]$infile[/navy][teal]][/teal][teal]}[/teal] [teal]{[/teal]
  [b]set[/b] line [teal][[/teal][b]gets[/b] [navy]$infile[/navy][teal]][/teal]
  [b]if[/b] [teal]{[/teal][navy]$line[/navy][teal]==[/teal][teal]{}}[/teal] [teal]{[/teal] [b]continue[/b] [teal]}[/teal]

  [b]set[/b] four [teal][[/teal][b]string[/b] range [navy]$line[/navy] [purple]0[/purple] [purple]3[/purple][teal]][/teal]

  [b]if[/b] [teal]{[/teal][teal][[/teal][b]lsearch[/b] [teal]-[/teal]exact [navy]$x[/navy] [navy]$four[/navy][teal]]==-[/teal][purple]1[/purple][teal]}[/teal] [teal]{[/teal]
    [b]puts[/b] [navy]$outfile[/navy] [teal][[/teal][b]format[/b] [green][i]"C;X[llength $x];Y1;K[/i][/green][lime][i]\"[/i][/lime][green][i]%s[/i][/green][lime][i]\"[/i][/lime][green][i]"[/i][/green] [teal][[/teal][b]expr[/b] [teal]{[/teal][teal][[/teal]array names title [teal]-[/teal]exact [navy]$four[/navy][teal]]!=[/teal][teal]{}[/teal][teal]?[/teal][navy]$title[/navy][teal]([/teal][navy]$four[/navy][teal]):[/teal][green][i]"The ${four}s"[/i][/green][teal]}[/teal][teal]]][/teal]
    [b]lappend[/b] x [navy]$four[/navy]
    [b]set[/b] y[teal]([/teal][navy]$four[/navy][teal])[/teal] [purple]1[/purple]
  [teal]}[/teal]

  [b]incr[/b] y[teal]([/teal][navy]$four[/navy][teal])[/teal]

  [b]puts[/b] [navy]$outfile[/navy] [green][i]"C;X[lsearch -exact $x $four];Y$y($four);K[/i][/green][lime][i]\"[/i][/lime][green][i]$line[/i][/green][lime][i]\"[/i][/lime][green][i]"[/i][/green]
[teal]}[/teal]

[b]puts[/b] [navy]$outfile[/navy] [green][i]"E"[/i][/green]

[b]close[/b] [navy]$outfile[/navy]
[b]close[/b] [navy]$infile[/navy]

Feherke.
 
What's that for a text file format *.SLK ?
Code:
ID;PSCALC3
C;X1;Y1;K"One"
C;X1;Y2;K"1187xx"
C;X2;Y1;K"Other"
C;X2;Y2;K"1148xx"
C;X3;Y1;K"The 1200s"
C;X3;Y2;K"1200xx"
C;X1;Y3;K"1187xx"
C;X2;Y3;K"1148xx"
C;X4;Y1;K"The 1100s"
C;X4;Y2;K"1100xx"
E
And it opens automatically in Excels - like CSV.

Never seen such thing before.
 
Hi

mikrom said:
What's that for a text file format *.SLK ?
"What's that" is a frequent question around the SyLk. It is Microsoft invention, so it is
[ul]
[li]best handled in Excel[/li]
[li]poorly documented, mostly by enthusiasts of the format[/li]
[/ul]
The best information I can recommend is the SYmbolic LinK (SYLK) | SYLK Syntax section of the Wikipedia article.
Code:
ID;PSCALC3       [gray]# generator identifier, must be the first[/gray]
C;X1;Y1;K"One"   [gray]# cell, in column C, row Y, has the given value[/gray]
E                [gray]# end mark, must be the last[/gray]
( Note, there are no comments in SyLk, the above comments are making it invalid. )
mikrom said:
And it opens automatically in Excels - like CSV.
Or in OpenOffice.org Calc. But the formatting are fully supported only by Excel.
mikrom said:
Never seen such thing before.
Hmm... Never looked in the Save as drop-down of your spreadsheet editor's Open/Save dialog ? ;-)

Another, somehow similar format is Data Interchange Format. But its structure is not suitable for the random-access writing used in my latest script.


Feherke.
 
I looked now in Excel Open/Save dialog and I see: SYLK (Symbolic Link) is there.

As I understood from the description on the link you posted, you can inlude in SYLK the formulae for computing too. Very interesting format.

Thank you very much!
 
Hi

mikrom said:
As I understood from the description on the link you posted, you can inlude in SYLK the formulae for computing too.
Yes, with one big PITA :
[ul]
[li]Excel understands only R1:C1 field references[/li]
[li]OpenOffice.org Calc understands only A1 field references[/li]
[/ul]


Feherke.
 
Thank you so much guys, Feherke and Miikrom.

You have answered all my questions excellently, you are both geniuses.. :)

And im sorry if i did not explain my question better enough at first.

Thanks again.

-Daisy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top