File Handler in TCL


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File Handler in TCL
# 1  
Old 09-06-2005
Tools File Handler in TCL

Hai ,

I Have Some x.txt file in which has the following data

x.txt

HI, How Are u
r u fine
/home/Sanju/samp.html
/root/Sanju/design/sample


now in tcl i have the following script

set fp [open x.txt r+ 0600]
while { [gets $fp line ] >= 0 } {
puts $line
}
close $fp


now if i run the program the lines in the file will be displayed one after the other ,

but now i want to display the file in different order like

1. first line to last line
2 .last line to first line
3 . display 1,3 ,5 and then 2,4 ,etc but all lines must display

how can i do that
plz help me

Smilie
Sanju
# 2  
Old 04-24-2007
two ways to do this....

one is:

set fhndl [open "filename" r]
gets $fhndl line
while {$line != ""} {
puts $line
gets $fhndl line
}
close $fhndl

other is:

set fhndl [open "filename" r]
set all [read $fhndl]
set lines [split $all "\n"]
foreach line $lines {
# do line processing here
}
close $fhndl



REST ALL YOU CAN BUILD AROUND THIS.....
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

TCL script to insert some text on a file

Hi All , I am looking to create one TCL script to insert one text based on some regular expression match on one file as stated below Input File module (mem1 ,mem2 , bist1 , ten2 , sen1 , land2 , taane2 , ran1 , ran2 , tri2 , tri8 , fly1 , fly2 , san2 ); output ran1 , ran2 , tri2 ,... (1 Reply)
Discussion started by: kshitij
1 Replies

2. Shell Programming and Scripting

Need to call tcl function from other file !!

Hi, Can a function written in tcl in some other file be called in unix scripts ? Like this ? This is my code now--- shell.sh: #!/bin/bash tclsh snmpv2-conf-sam.tcl $SERVER $NODESYSIP $SPASSWD but i need this in a different way like , without having a .tcl file i want the... (2 Replies)
Discussion started by: giri_luck
2 Replies

3. Programming

File handling in TCL

Hi, I have n number of files in a directory with extension .PGM i need to store the full path name in a variable and only the file name with extension in another variable. Each time i'll be using the next file name for manipulation. Please help me out to do this using TCL thanks (1 Reply)
Discussion started by: Syed Imran
1 Replies

4. Programming

TCL reading file

This is the code i have to read and display each line every time. please let me know the bug in this.. am not getting the output set fp set file_data close $fp set data foreach line $data { puts $data } content of abc.txt is ... (1 Reply)
Discussion started by: Syed Imran
1 Replies

5. UNIX for Dummies Questions & Answers

File Handler of an Output

Hi Guys, I hope anyone could help me on my problem: (perl or shell) I have this command: ns cluster "ns snmp show status" all Then the output is: Command was launched from partition 0. ------------------------------------------------ Executing command in server server6 Event Text... (3 Replies)
Discussion started by: rymnd_12345
3 Replies

6. UNIX for Advanced & Expert Users

File Format in TCL

Hi, Can anyone please guide me in writing a TCL script. I want to have a procedure to recreate an existing file and backup its copy and rename it by time of the updates are made. Eg: I have file xyz.tcl (which on recreation is saved as xyz_11jan_15_30_11.tcl) So when I do % ls... (1 Reply)
Discussion started by: mail2leo
1 Replies

7. Programming

Parsing a text file in Tcl

Hi all, I need to parse through a text file searching for a specific string, then after I find this string read in remaining data off the line to a variable. I've tried various things and can't seem to get any to work. Any help would be much appreciated. (2 Replies)
Discussion started by: caboose57
2 Replies

8. Shell Programming and Scripting

TCL Reading file from Server

I'm nearly finished developing my app, im programming it in tcl/tk. I just need to get 1 last thing done. When my app starts, i ask the user for username and password. These are stored on a file on a unix server. My problem is how do i read a file from a unix server, i've tried everything but... (3 Replies)
Discussion started by: Phi01
3 Replies

9. Shell Programming and Scripting

Passing a file handler and an array from Perl to Shell Script

Hi there, I am trying to call a shell script from a Perl script. here is the code: @args = ("sh", "someshellprg.sh", "a file handler", "an array"); system(@args) == 0 or die "system @args failed: $?"; in the shell program, I examine if the arguments exits using: if then echo... (5 Replies)
Discussion started by: pinkgladiator
5 Replies

10. UNIX for Dummies Questions & Answers

Reading line from file - TCL

I Have output of ps -ef in file. while reading from file, it reads one word but i want to read the full line. Is there any way to set IFS in TCL as we set in Shell. Thanks Ajay Kumar (2 Replies)
Discussion started by: aju_kup
2 Replies
Login or Register to Ask a Question