# Need help with simple root to text file command

**URL:** <https://root-forum.cern.ch/t/need-help-with-simple-root-to-text-file-command/35309>\
**Category:** Newbie\
**Created:** [July 23, 2019, 2:39pm UTC](https://root-forum.cern.ch/t/need-help-with-simple-root-to-text-file-command/35309 "2019-07-23T14:39:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeonyboy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jeonyboy/32/19388_2.png) [@jeonyboy](https://root-forum.cern.ch/u/jeonyboy)\
**Post date:** [July 23, 2019, 2:39pm UTC](https://root-forum.cern.ch/t/need-help-with-simple-root-to-text-file-command/35309/1 "2019-07-23T14:39:54Z")

</div>

Hello, I used to use the below command to extract root data and write to a text file. My computer got wiped and I got the latest version of root and it does not work anymore. I am not great with C language so if anyone could revise the command for me I would appreciate it so much.

TFile \*f = TFile::Open(“ALL1\_10nm5fc.root”); TH1D \*h2 = (TH1D \*)f-\>Get(“1”); h2-\>Print(“all”); \> h2.txt

* * *

_ROOT Version:_ v6.16.00  
_Platform:_ windows 7  
_Compiler:_ visual studio 2017

* * *

---

<div class="post-metadata">

**Author:** ![jeonyboy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jeonyboy/32/19388_2.png) [@jeonyboy](https://root-forum.cern.ch/u/jeonyboy)\
**Post date:** [July 23, 2019, 2:41pm UTC](https://root-forum.cern.ch/t/need-help-with-simple-root-to-text-file-command/35309/2 "2019-07-23T14:41:01Z")

</div>

![root](https://root-forum.cern.ch/uploads/default/original/3X/4/e/4e0c3a89f4252d3ceb48e88b88e916d909c7e29e.png)  
I am trying to extract 1;1 and have it written as text file with x,y

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [July 23, 2019, 2:54pm UTC](https://root-forum.cern.ch/t/need-help-with-simple-root-to-text-file-command/35309/3 "2019-07-23T14:54:42Z")

</div>

```cpp
root[0] TFile *f = TFile::Open("ALL1_10nm5fc.root"); 
root[1] TH1D *h2 = (TH1D *)f->Get("1"); 
root[2] .> h2.txt
h2->Print("all"); 
.>

```

---

<div class="post-metadata">

**Author:** ![jeonyboy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jeonyboy/32/19388_2.png) [@jeonyboy](https://root-forum.cern.ch/u/jeonyboy)\
**Post date:** [July 24, 2019, 1:42am UTC](https://root-forum.cern.ch/t/need-help-with-simple-root-to-text-file-command/35309/4 "2019-07-24T01:42:47Z")

</div>

Thank you for your reply! When I copy and paste your answer I get the following error.

 ![root2](https://root-forum.cern.ch/uploads/default/original/3X/b/4/b4a53a5a7378a2a316a24ca5bd94dbf8ef033502.png)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [July 24, 2019, 7:04am UTC](https://root-forum.cern.ch/t/need-help-with-simple-root-to-text-file-command/35309/5 "2019-07-24T07:04:31Z")

</div>

You should not copy the prompts. I put them to show you it’s a multiline process.  
Copy/paste the following:

```auto
TFile *f = TFile::Open("ALL1_10nm5fc.root"); 
TH1D *h2 = (TH1D *)f->Get("1"); 
.> h2.txt
h2->Print("all"); 
.>

```

---

<div class="post-metadata">

**Author:** ![jeonyboy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jeonyboy/32/19388_2.png) [@jeonyboy](https://root-forum.cern.ch/u/jeonyboy)\
**Post date:** [July 25, 2019, 1:12am UTC](https://root-forum.cern.ch/t/need-help-with-simple-root-to-text-file-command/35309/6 "2019-07-25T01:12:42Z")

</div>

I did try it without the root before without success. I tried copy and paste your answer and I still get an error. I solved it by just downloading root5 instead of root6. I would like to solve it though still.

 ![root3](https://root-forum.cern.ch/uploads/default/original/3X/d/5/d5b541c4c52b735e96b9f079d3f09dd3a7c782b3.png)

---

<div class="post-metadata">

**Author:** ![sbinet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/sbinet/32/13166_2.png) [@sbinet](https://root-forum.cern.ch/u/sbinet)\
**Post date:** [July 29, 2019, 1:07pm UTC](https://root-forum.cern.ch/t/need-help-with-simple-root-to-text-file-command/35309/7 "2019-07-29T13:07:42Z")

</div>

in case everything else fails, you could either use `root-dump` or `root2yoda` (2 binaries from [GoHEP](https://go-hep.org).)

see:

- [How to convert .root to .txt file?](https://root-forum.cern.ch/t/how-to-convert-root-to-txt-file/30534/3)
- [Root2yoda with Go-HEP](https://root-forum.cern.ch/t/root2yoda-with-go-hep/25981)
