From: Bart on
Hello,

I'm trying to open a text file with text and data, and want to delete
the last 16 characters of every line. Example:

I have:


XFOIL Version 6.93

Calculated polar for: NACA
63-415

1 1 Reynolds number fixed Mach number fixed

xtrf = 1.000 (top) 1.000 (bottom)
Mach = 0.000 Re = 1.000 e 6 Ncrit = 9.000

alpha CL CD CDp CM Top_Xtr Bot_Xtr
CQ CDq
------- -------- --------- --------- -------- ------- -------
-------- --------
-3.500 -0.0619 0.00657 0.00152 -0.0747 0.6538 0.4219
0.00000 0.00000
-3.250 -0.0328 0.00651 0.00146 -0.0750 0.6465 0.4423
0.00000 0.00000
-2.500 0.0554 0.00639 0.00134 -0.0759 0.6326 0.4869
0.00000 0.00000
-2.250 0.0846 0.00638 0.00131 -0.0762 0.6250 0.4968
0.00000 0.00000

and I want:


XFOIL Version 6.93

Calculated polar for: NACA 63-415

1 1 Reynolds number fixed Mach number fixed

xtrf = 1.000 (top) 1.000 (bottom)
Mach = 0.000 Re = 1.000 e 6 Ncrit = 9.000

alpha CL CD CDp CM Top_Xtr Bot_Xtr
------- -------- --------- --------- -------- ------- -------
-3.500 -0.0619 0.00657 0.00152 -0.0747 0.6538 0.4219
-3.250 -0.0328 0.00651 0.00146 -0.0750 0.6465 0.4423
-2.500 0.0554 0.00639 0.00134 -0.0759 0.6326 0.4869
-2.250 0.0846 0.00638 0.00131 -0.0762 0.6250 0.4968

I tried a lot of different ways with textscan and fprintf, but it
didn't give me the desired result. Can anybody help me? Thanks a lot!

Bart
From: Rune Allnor on
On 15 apr, 11:08, Bart <bartnewsgr...(a)gmail.com> wrote:
> Hello,
>
> I'm trying to open a text file with text and data, and want to delete
> the last 16 characters of every line. Example:

> I tried a lot of different ways with textscan and fprintf, but it
> didn't give me the desired result. Can anybody help me? Thanks a lot!

There is only one way to do this:

1) Open the input file
2) Open a temporary output file
3) Read the next line from the input file into a string
4) Scan the string to find out what caharcters to delete
5) Delete characters and store the edited line to a new string
6) Write the edited string to the temporary output
7) If input file not empty, repeat from 3)
8) Close both files
9) Delete input file
10) Rename the temporary file to original input file name

Rune