Change space in file to tab

Hey Root User,

I am currently using root for my data analysis in my internship and have a question. I have an Asci file (.txt) and have there about 9000 entries these are not separated with a tab but with a space. Root wants to be able to evaluate it tabs how can I change this ?

Where exactly ROOT requires tabs?

I mean when reading out the data. These must be separated with a tab not with a space.

The Error:

*** Break *** segmentation violation
Generating stack trace…
0x00007fcdc99e9046 in from /snap/root-framework/889/usr/local/lib/libCore.so
0x00007fcdc9198090 in from /lib/x86_64-linux-gnu/libc.so.6
0x00007fcdc92e09d3 in from /lib/x86_64-linux-gnu/libc.so.6
0x00007fcdac64e5fa in TGraph::CopyPoints(double**, int, int, int) + 0xa4 from /snap/root-framework/889/usr/local/lib/libHist.so
0x00007fcdac64f9fa in TGraph::ExpandAndCopy(int, int) + 0x7c from /snap/root-framework/889/usr/local/lib/libHist.so
0x00007fcdac655415 in TGraph::SetPoint(int, double, double) + 0x6f from /snap/root-framework/889/usr/local/lib/libHist.so
0x00007fcdc954b228 in
0x00007fcdc954e03f in
0x00007fcdc35669f6 in from /snap/root-framework/889/usr/local/lib/libCling.so
0x00007fcdc34cfeff in from /snap/root-framework/889/usr/local/lib/libCling.so
0x00007fcdc34d2d45 in from /snap/root-framework/889/usr/local/lib/libCling.so
0x00007fcdc35e4271 in from /snap/root-framework/889/usr/local/lib/libCling.so
0x00007fcdc35f3ec5 in from /snap/root-framework/889/usr/local/lib/libCling.so
0x00007fcdc35f5778 in from /snap/root-framework/889/usr/local/lib/libCling.so
0x00007fcdc35dced0 in from /snap/root-framework/889/usr/local/lib/libCling.so
0x00007fcdc327661f in from /snap/root-framework/889/usr/local/lib/libCling.so
0x00007fcdc32770b5 in TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) + 0x8e3 from /snap/root-framework/889/usr/local/lib/libCling.so
0x00007fcdc327acea in TCling::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) + 0xa6 from /snap/root-framework/889/usr/local/lib/libCling.so
0x00007fcdc984e460 in TApplication::ExecuteFile(char const*, int*, bool) at TApplication.cxx:? from /snap/root-framework/889/usr/local/lib/libCore.so
0x00007fcdc984dbbe in TApplication::ProcessFile(char const*, int*, bool) + 0x34 from /snap/root-framework/889/usr/local/lib/libCore.so
0x00007fcdc984d9aa in TApplication::ProcessLine(char const*, bool, int*) + 0xd4a from /snap/root-framework/889/usr/local/lib/libCore.so
0x00007fcdc9c173dc in TRint::ProcessLineNr(char const*, char const*, int*) + 0x332 from /snap/root-framework/889/usr/local/lib/libRint.so
0x00007fcdc9c169d3 in TRint::HandleTermInput() + 0x2e1 from /snap/root-framework/889/usr/local/lib/libRint.so
0x00007fcdc9c13f59 in TTermInputHandler::Notify() + 0x35 from /snap/root-framework/889/usr/local/lib/libRint.so
0x00007fcdc9c18db7 in TTermInputHandler::ReadNotify() + 0x29 from /snap/root-framework/889/usr/local/lib/libRint.so
0x00007fcdc99f2af9 in TUnixSystem::CheckDescriptors() + 0x121 from /snap/root-framework/889/usr/local/lib/libCore.so
0x00007fcdc99f1d56 in TUnixSystem::DispatchOneEvent(bool) + 0x178 from /snap/root-framework/889/usr/local/lib/libCore.so
0x00007fcdc98c96e7 in TSystem::InnerLoop() + 0x45 from /snap/root-framework/889/usr/local/lib/libCore.so
0x00007fcdc98c9458 in TSystem::Run() + 0xf4 from /snap/root-framework/889/usr/local/lib/libCore.so
0x00007fcdc984e631 in TApplication::Run(bool) + 0x61 from /snap/root-framework/889/usr/local/lib/libCore.so
0x00007fcdc9c15d46 in TRint::Run(bool) + 0x8da from /snap/root-framework/889/usr/local/lib/libRint.so
0x00005589275245dd in main + 0x87 from /snap/root-framework/889/usr/local/bin/root.exe
0x00007fcdc9179083 in __libc_start_main + 0xf3 from /lib/x86_64-linux-gnu/libc.so.6
0x000055892752424e in _start + 0x2e from /snap/root-framework/889/usr/local/bin/root.exe
Root >

What exactly are you doing?

#include “TGraphPainter.h”
#include “TCanvas.h”
#include “TGraph.h”
#include “TMath.h”
#include

void Macroaufgabe1()
{
TGraph *gr= new TGraph();

	gr -> SetMarkerStyle(kFullCircle);
	
	
	  ifstream file;
 	  file.open("Aufgabe323.txt", ios::in);

std::cout<<file.is_open()<<std::endl;
while(1)
{
double x,y ;
file >> x >> y;
gr → SetPoint(gr->GetN(),x,y);
if(file.eof()) break;
}

file.close();

TCanvas *c1 = new TCanvas() ;
gr->Draw("AP") ;

}

This is my code for Plot my data points from my .txt data

Attach “Aufgabe323.txt” for inspection.
Or post first several lines here.

It could be that this works:

{
  TGraph *gr = new TGraph("Aufgabe323.txt");
  gr->Draw("AP");
}

I am a new user i dont cant make attach. But here a short copy paste:

────+───────────+
| t      | Phi(t)    |
+────────+───────────+
| 0      | 88.876    |
| 0.005  | 90.702    |
| 0.01   | 92.529    |
| 0.015  | 94.355    |
| 0.02   | 96.18     |
| 0.025  | 98.003    |
| 0.03   | 99.825    |
| 0.035  | 101.644   |
| 0.04   | 103.46    |
| 0.045  | 105.273   |
| 0.05   | 107.082   |
| 0.055  | 108.887   |
| 0.06   | 110.686   |

O.K.
You need to get rid of all “|”, “”, and “+” characters (and remove the line with “t” and “Phi(t)”).
Then my simple macro will work.
Your file should look like this:

 0       88.876    
 0.005   90.702    
 0.01    92.529    

it works thanks !!!

You can use for example the text editor geany to autoconvert all tabs to spaces upon file saving.
Or using search-replace.

I don’t think there is any need to convert between spaces and tabs.
Anyhow, the easiest would be:
sed -i -e '{s/ /\t/g}' myfile.txt # spaces to tabs
sed -i -e '{s/\t/ /g}' myfile.txt # tabs to spaces

BTW. The original file could easily be “cleaned” using (if there is no “scientific / exponential notation” used):
sed -i -e '{s/[^[:space:]0-9.-]//g}' Aufgabe323.txt

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.