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

how to remove the blank line from a file?? 1

Status
Not open for further replies.

RajVerma

Programmer
Jun 11, 2003
62
DE
hi,

I open a file in r+ mode and read the data line by line. when I encounter an empty line I want to delete it.

I found the info on deleting text in the widgets, but I cudn't manage to do it inside a file!

any help...

thnx,
Raj.
 
I don't think you can delete a line in a file, without, that is, making the previous line the last one!. There are plenty of ways around this but not the way you're trying to do it. Two obvious ones that come to mind are to open your file for reading and a temporary one for writing. Then read each line and write it to the temp file if it isn't blank. At the end, delete the original file and rename the temp file to the original file name.

The other is to open the file for reading, then read the whole file in as a list of lines (set linelist [split [read $fid] \n]). Then remove blanks from the list and write it out to the same file opened for writing.

Bob Rashkin
rrashkin@csc.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top