Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

printing newline character

kingsleyuk2003 (Programmer) (OP)
9 Jul 08 12:14
Please how can i print a newline character into a file, let say I have an information ABCDEF in a file 1. how can i make these letters appear in another file 2. in this format
A
B
C
D
E
F
thanks
Bong (Programmer)
9 Jul 08 12:49
The newline character is \n.  Also, puts will insert a newline after each execution unless the -nonewline option is specified.

So you have a couple of options depending on how the original data are organized.  Let's say you read the entire dataset from the input as a single string, say strA:

CODE

set fid [open <input file name> r]
set strA [read $fid]
close $fid
Now you could parse strA and insert \n where you want it, and then

CODE

set fid [open <output file name> w]
puts -nonewline $fid $strA; #the newlines are already there
close $fid
Alternatively, you could parse the input on the read.  Let's say each line will have a fixed number of bytes:

CODE

set fid [open <input file name> r]
while ![eof $fid] {
  lappend lstA [read $fid <number of bytes>]
}
close $fid
set fid [open <output file name> w]
foreach lineA $lstA {
  puts $fid $lineA
}
close $fid
Your data may be more complicated than this.  If you tell us how the lines are to be configured, maybe we can help with that.

_________________
Bob Rashkin

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close