Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • 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!
  • Students Click Here

*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.

Students Click Here


printing newline character

printing newline character

printing newline character

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

RE: printing newline character

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:


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


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:


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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

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!

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