# Write TTree to TXT?

**URL:** <https://root-forum.cern.ch/t/write-ttree-to-txt/11651>\
**Category:** ROOT\
**Created:** [January 7, 2011, 10:06pm UTC](https://root-forum.cern.ch/t/write-ttree-to-txt/11651 "2011-01-07T22:06:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cjrd](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/4da419/32.png) [@cjrd](https://root-forum.cern.ch/u/cjrd)\
**Post date:** [January 7, 2011, 10:06pm UTC](https://root-forum.cern.ch/t/write-ttree-to-txt/11651/1 "2011-01-07T22:06:12Z")

</div>

Hello,

Does anyone know of a simple way to write a TTree to a TXT (CSV) file? Reading a TXT file into a TTree can be accomplished in one line and I was curious if anyone knows of an equivalent way to do this in “reverse.”

For example, to read a tab/space delimited text that has 4 columns file into a TTree (T):

```auto
T->ReadFile ("Data.txt","var1:var2:var3:var4");
```

Is there a simple way to take T and write the text file?

Thanks,

Colorado

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [January 9, 2011, 9:44pm UTC](https://root-forum.cern.ch/t/write-ttree-to-txt/11651/2 "2011-01-09T21:44:28Z")

</div>

Hi,

```auto
T->Scan("*"); >T.txt

```

should work (with ROOT 5).

Cheers, Axel.

---

<div class="post-metadata">

**Author:** ![cjrd](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/4da419/32.png) [@cjrd](https://root-forum.cern.ch/u/cjrd)\
**Post date:** [January 9, 2011, 11:21pm UTC](https://root-forum.cern.ch/t/write-ttree-to-txt/11651/3 "2011-01-09T23:21:58Z")

</div>

Thanks for the response, your solution sent me down the right path.

A side note for anyone else:

```auto
T->SetScanField(0)
T->Scan("*"); >output.txt
```

Will allow the data to be streamed into output.txt without any prompts or displaying the data to the screen.

---

<div class="post-metadata">

**Author:** ![cristella](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/cristella/32/16288_2.png) [@cristella](https://root-forum.cern.ch/u/cristella)\
**Post date:** [May 16, 2018, 4:49pm UTC](https://root-forum.cern.ch/t/write-ttree-to-txt/11651/4 "2018-05-16T16:49:24Z")

</div>

Hello,  
I do not see any solution provided here.  
Maybe the link/attached file has been lost?

Cheers,  
Leonardo

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [May 16, 2018, 8:47pm UTC](https://root-forum.cern.ch/t/write-ttree-to-txt/11651/5 "2018-05-16T20:47:50Z")

</div>

Hi Leonardo, in 7 years much changed! Would you open a new thread to get support?

Cheers,  
D
