Computing.Net > Forums > Windows XP > Batch file to edit text file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch file to edit text file

Reply to Message Icon

Name: shellhrs
Date: November 3, 2006 at 04:10:06 Pacific
OS: Win XP SP2
CPU/Ram: Celeron 1.8GHz 256Mb
Comment:

Hi,

I need a batch file to edit a text file.

This file contains test results from a program. The data is separated by spaces and "00000" (space and numbers as delimiter?). I need to have each of them moved to different lines. I also need to have characters "00" inserted at the beginning of each line.

Input (what I have):
123 alpha test 1 00000 223.3

Output (what I need):
123 alpha
00 test 1 223.3

Can anyone help me, please?

Thanks in advance.



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: November 3, 2006 at 04:36:55 Pacific
Reply:

@echo off > newfile
setLocal EnableDelayedExpansion

for /f "tokens=* delims=" %%N in (myfile) do (
call :sub1 %%N
)
goto :eof

:sub1
>> newfile echo %1 %2
>> newfile echo 00 %3 %4 %6
goto :eof


=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 2
Name: shellhrs
Date: November 5, 2006 at 21:21:02 Pacific
Reply:

Mechanix2Go, thanks for the quick reply.

I will try it now.


0

Response Number 3
Name: shellhrs
Date: November 7, 2006 at 02:45:49 Pacific
Reply:

Apparently I didn't type the sample correctly for the message format. Some of the empty spaces were missing.

Here's the input file (4 lines; 0C - 5, 0RED - 00000, 0YELL - 00000, 0BLUE - 00000):

0C Service [6 spaces] 21 [23 spaces] 0 [9 spaces] 3 [33 spaces] 5 [9 spaces] 5
0RED ACE [16 spaces] 0.5669 [4 spaces] 00000
0YELL ACE [15 spaces] 0.7727 [4 spaces] 00000
0BLUE ACE [15 spaces] 0.1969 [4 spaces] 00000

And this is the output file I need (4 lines; 021 - 5, 0T - 00000, 0T - 00000, 0T - 00000):

021 [13 spaces] C SERVICE [16 spaces] 0 [9 spaces] 3 [33 spaces] 4 [9 spaces] 5
0T [2 spaces] RED ACE [3 spaces] 0.0000 [4 spaces] 0.5669 [4 spaces] 00000
0T [2 spaces] YELL ACE [2 spaces] 0.0000 [4 spaces] 0.7727 [4 spaces] 00000
0T [2 spaces] BLUE ACE [2 spaces] 0.0000 [4 spaces] 0.1969 [4 spaces] 00000

Mechanix2Go, I really appreciate your help. I tried to modify the batch file you gave, but it just wouldn't let me use all those variables. I found out that the maximum number of variables is 10 (%0 - %9), while I have 19 variables. Also, I couldn't separate the 0s from the C, RED, YELL, BLUE.

Could anyone help me? Sorry about the [spaces], but I need the empty spaces between the variables -- basically I need all the numbers in columns.

Thank you.


0

Response Number 4
Name: Mechanix2Go
Date: November 7, 2006 at 03:31:06 Pacific
Reply:

You got me mystified.

Maybe you can send me two files, the orig and the needed.


=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 5
Name: shellhrs
Date: November 7, 2006 at 20:58:56 Pacific
Reply:

Mechanix2Go,

Thank you your prompt response. I will be sending you the two files (input and output).

I really appreciate your help!


0

Related Posts

See More



Response Number 6
Name: Mechanix2Go
Date: November 7, 2006 at 22:55:42 Pacific
Reply:

Got 'em.

Where does the 0.0000 in the 4th column of lines 2~4 come from?



=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 7
Name: shellhrs
Date: November 8, 2006 at 20:33:42 Pacific
Reply:

The "T" in the first column of "0T" were to be added because it was not in the input file.

So do the "0.0000" in the third column. They were supposed to be added using the batch file.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Windows XP Forum Home


Sponsored links

Ads by Google


Results for: Batch file to edit text file

Several DOS Batch Files, Need help www.computing.net/answers/windows-xp/several-dos-batch-files-need-help/141749.html

read,edit text file using bat file www.computing.net/answers/windows-xp/readedit-text-file-using-bat-file/173542.html

Batch file to capture ping response times www.computing.net/answers/windows-xp/batch-file-to-capture-ping-response-times/179253.html