How to add a perl or awk code inside a root macro

I was trying to select some values from a .txt file with the format

[code] ==================================================================
Calculation using SRIM-2006
SRIM version —> SRIM-2008.04
Calc. date —> December 05, 2013

Disk File Name = SRIM Outputs\Helium in Silicon

Ion = Helium [2] , Mass = 4.003 amu

Target Density = 2.3212E+00 g/cm3 = 4.9770E+22 atoms/cm3
======= Target Composition ========
Atom Atom Atomic Mass
Name Numb Percent Percent
---- ---- ------- -------
Si 14 100.00 100.00

Bragg Correction = 0.00%
Stopping Units = MeV / (mg/cm2)
See bottom of Table for other Stopping units

Ion dE/dx dE/dx Projected Longitudinal Lateral
Energy Elec. Nuclear Range Straggling Straggling


500.00 keV 1.452E+00 3.238E-03 1.98 um 1891 A 2389 A
550.00 keV 1.449E+00 2.999E-03 2.13 um 1921 A 2443 A
600.00 keV 1.441E+00 2.795E-03 2.27 um 1951 A 2495 A
650.00 keV 1.430E+00 2.619E-03 2.42 um 1979 A 2545 A
700.00 keV 1.416E+00 2.466E-03 2.57 um 2007 A 2594 A
800.00 keV 1.384E+00 2.211E-03 2.88 um 2084 A 2689 A
900.00 keV 1.349E+00 2.007E-03 3.19 um 2160 A 2782 A
1.00 MeV 1.312E+00 1.839E-03 3.51 um 2237 A 2874 A
1.10 MeV 1.276E+00 1.700E-03 3.84 um 2314 A 2967 A
1.20 MeV 1.240E+00 1.581E-03 4.18 um 2392 A 3060 A
1.30 MeV 1.206E+00 1.479E-03 4.53 um 2471 A 3153 A
1.40 MeV 1.172E+00 1.390E-03 4.89 um 2551 A 3249 A
1.50 MeV 1.141E+00 1.312E-03 5.26 um 2633 A 3345 A
1.60 MeV 1.111E+00 1.243E-03 5.65 um 2716 A 3444 A
1.70 MeV 1.082E+00 1.181E-03 6.04 um 2801 A 3544 A
1.80 MeV 1.055E+00 1.126E-03 6.44 um 2888 A 3647 A
2.00 MeV 1.005E+00 1.030E-03 7.27 um 3176 A 3858 A
2.25 MeV 9.495E-01 9.320E-04 8.37 um 3605 A 4135 A
2.50 MeV 9.002E-01 8.522E-04 9.53 um 4031 A 4426 A
2.75 MeV 8.564E-01 7.857E-04 10.75 um 4456 A 4732 A
3.00 MeV 8.172E-01 7.294E-04 12.04 um 4883 A 5053 A
3.25 MeV 7.821E-01 6.811E-04 13.38 um 5312 A 5388 A
3.50 MeV 7.503E-01 6.391E-04 14.78 um 5744 A 5737 A
3.75 MeV 7.214E-01 6.024E-04 16.24 um 6180 A 6101 A
4.00 MeV 6.950E-01 5.698E-04 17.76 um 6619 A 6478 A
4.50 MeV 6.486E-01 5.148E-04 20.96 um 8162 A 7272 A
5.00 MeV 6.090E-01 4.700E-04 24.38 um 9630 A 8118 A

Multiply Stopping by for Stopping Units


2.3211E+01 eV / Angstrom
2.3211E+02 keV / micron
2.3211E+02 MeV / mm
1.0000E+00 keV / (ug/cm2)
1.0000E+00 MeV / (mg/cm2)
1.0000E+03 keV / (mg/cm2)
4.6637E+01 eV / (1E15 atoms/cm2)
4.2914E+00 L.S.S. reduced units

© 1984,1989,1992,1998,2008 by J.P. Biersack and J.F. Ziegler[/code]

I used perl and awk to selecet the columns and data that I needed. The perl code is

[code]use strict;
use warnings;

my $content = do { local $/; <> };
my ($table) = $content =~ /-----\n(.+?)\n-----/s;

while ( $table =~ /(\S+)\s+([kM]eV).+?(\S+)\s+um/g ) {
print $2 eq ‘keV’ ? $1 * 1000 : $1;
print “\t$3\n”;
}[/code]

and it’s executed using

Then I use a simle macro to plot from the processed.txt file.

The awk line that I use is

Is there a way to add one of those code lines on a root macro?

I know that awk and perl are C based, but I can’t just put them in my macro because it wouldn’t work.

Hello,
maybe you may use some methods from TSystem
For example, you can write

to run your perl script
After that you may use GetFromPipe to get the output of your awk command.

Might find something useful at Perl tutorials & books.