Solved Batch edit files, extract lines of text into new text doc

March 4, 2013 at 10:26:30
Specs: Windows XP
I have many text files that need to be edited in the exact same way. They are machine tool instructions that were copied off floppy discs, and the resulting string is represented below. The following is one string of commands of many like this within each original text doc.....the $ marks the begin character of the string, and the M2 % marks the end character. What I need to do, is be able to batch separate these instructions from the long string in each original file, beginning and ending with the above referenced characters, then copy and paste each separated instruction string, into a new text file, and be able to name this new file with the instruction name shown at the beginning of the original string (in this example, the first would be "ADSCO-RING4.MIN"). My example below is what needs to be copied-n-pasted into separate new text files.

Anyone know of a simple way to accomplish? I'm using Windows XP. Thanks!!!

 $ADSCO-RING4.MIN %
( ADSCO SK-33589-4 RING )
G15 H1
G56 H1 ( SPOT )
M3 S1600
/M8
G71 Z1.5
G81 X2.2483 Y5.4278 R.05 Z-.1 F4.0 M53
X5.4278 Y2.2483
Y-2.2483
X2.2483 Y-5.4278
X-2.2483
X-5.4278 Y-2.2483
Y2.2483
X-2.2483 Y5.4278
M9 T2
G0 Z20
M6
N2
G56 H2 ( 7/8 DRILL )
M3 S400
/M8
G71 Z1.5
G83 X2.2483 Y5.4278 R.05 Z-1.1 F2.0 Q.12 M53
X5.4278 Y2.2483
Y-2.2483
X2.2483 Y-5.4278
X-2.2483
X-5.4278 Y-2.2483
Y2.2483
X-2.2483 Y5.4278
M9 T3
G0 Z20
M6
N3
G56 H3 (CSINK)
M3 S350
/M8
G71 Z1.5
G81 X2.2483 Y5.4278 R.1 Z-.160 F2.0 M53
X5.4278 Y2.2483
Y-2.2483
X2.2483 Y-5.4278
X-2.2483
X-5.4278 Y-2.2483
Y2.2483
X-2.2483 Y5.4278
M9 T1
G0 Z20
X0 Y20
M6
M2
%


See More: Batch edit files, extract lines of text into new text doc

Report •

#1
March 4, 2013 at 12:04:24
I'm not sure I understand the situation. Do you have a large file that you need to split up on lines starting with "$", or do you need to strip out lines starting with "$" in a number of files?

How To Ask Questions The Smart Way


Report •

#2
March 4, 2013 at 14:11:09
Hi RAZOR2.3

First-off, I was mistaken on the original file-type....they are PRG files, not .txt files.

I'm going to post two LINKS here....they are screen captures of one of the PRG files opened with notepad. Each PRG file I have has 15 to 120 of these "strings" of machine commands. There is an ASCII character at the beginning and end of each string (looks like a hollow rectangle) which does not copy-n-paste here --- that's why I needed to show a screen capture of the file opened with a text editor. The original sample I posted on this blog would not show this ASCII character.

To answer your question, I need to strip-out the entire text BEGINNING WITH AND INCLUDING the ASCII character and the $, and ENDING WITH AND INCLUDING M2 % and the ASCII character.

Or, another way to put it is, I need to strip from one BEGINNING character, up to the next BEGINNING character. Then this stripped sentence needs to be placed into a new text file. I would then repeat these stripping steps until all sentences have been extracted individually to separate new text files.

Thanks for your help!!!
Dave

Here's the screen capture LINKS:

https://www.facebook.com/photo.php?...

https://www.facebook.com/photo.php?...


Report •

#3
March 4, 2013 at 19:57:29
✔ Best Answer
Here's a vbscript attempt, somewhat tested on limited (home-made) data:
'====== begin vbscript "mach"
set fso=createobject("scripting.filesystemobject")
s=split (fso.opentextfile(wscript.arguments(0),1).readall,"$")
ze=s(0)+"$"
for i=1 to ubound(s)
nexfil=left(s(i),instr(s(i),"%"))
fso.opentextfile(nexfil,2,true).write ze+s(i)
next
'===== end

Report •

Related Solutions

#4
March 5, 2013 at 01:37:18
Looks like these are not txt files, so not much hope with built-in Win tools.

Try CHANGE9X by Bruce Guthrie.

[No relation, I suppose to Arlo. :(]

=====================
M2 Golden-Triangle


Report •

#5
March 5, 2013 at 04:11:18
Here's a vbscript attempt, somewhat tested on limited (home-made) data:
'====== begin vbscript "mach"
set fso=createobject("scripting.filesystemobject")
s=split (fso.opentextfile(wscript.arguments(0),1).readall,"$")
ze=s(0)+"$"
for i=1 to ubound(s)
nexfil=left(s(i),instr(s(i),"%"))
fso.opentextfile(nexfil,2,true).write ze+s(i)
next
'===== end


Thanks for the possible solution here "nbrane"....I'm NOT a computer genius, so I have two questions:

1) You do realize I'm working with .PRG original files, correct?

2) If your solution above is OK, can you direct me as to how to execute? Is it added into a COMMAND LINE using "cmd.exe"?

Just need a little head-start! LOL
Thanks again!
Dave


Report •

#6
March 5, 2013 at 16:55:31
I guessed since the facebook screenshots showed using notepad, that these were text files. One of the possibilities, which looked appropriate: "RAPID program file", the www.fileinfo entry said it was openable with notepad, but other possibilities weren't ("PC-DMIS Part program CAD files", f/e). Maybe you can shed some light on this ;-)
As for running the vbscript, first cut/paste or otherwise place the vbscript text into the directory with the file you want to dissect (f/e, "Roboprog.prg"). Navigate to that directory, and from the command-prompt: CSCRIPT MACH.VBS Roboprog.prg
Of course, you can call the vbscript whatever name you wish, and you can also place the script wherever you want as long as you give full path: CSRIPT MACH.VBS \myfiles\roboprog, etc etc. (in other words, path-sync the project). The output files will appear in whatever directory you are in when you run the vbscript, (as written), not necessarily in the same dir as the PRG file and not nec. in the directory of the vbscript, so if you do: CD "%USERPROFILE%
CSCRIPT \myscripts\mach.vbs \myfiles\roboprog.prg
Your output files will be in %USERPROFILE%
Of course, all this is moot if the .PRG file is binary-type data.

Report •

#7
March 5, 2013 at 19:21:42
Hi nbrane!

I can tell you that I can manually open the .PRG files with notepad, then I can manually cut-n-paste the sentence that I want from the original string, and paste it into a new text file, and save it....The ASCII characters copy just fine, and the resulting new text file with one "sentence" of machine commands is all I need.

I do not know enough to tell you if the original file is binary or not....other than the one ASCII character (hollow rectangle), the rest appears to be just text.

As for beginning the job, are you saying to copy-n-paste the vbscript into a text file, then place this file in the same directory as the .PRG file I wish to dissect?

I'm sorry for being so picky, but I'm not very computer savvy when it comes to codes.

Thank you for your time and efforts! I hope to give this a try in the morning....would be even nicer if this were made into a more user-friendly utility program for us dummies!...LOL


Report •

#8
March 5, 2013 at 21:14:06
Hi again Dave: Nah, not picky. I never know how much needs to be made explicit, we get all levels of users in the forum, and I tend to assume where I should not presume to assume.
"As for beginning the job, are you saying to copy-n-paste the vbscript into a text file, then place this file in the same directory as the .PRG file I wish to dissect?"
Yes. If it works, the "subfiles" should appear, after running, in that same directory.

Vbscript can handle binary data in input stream, it's mostly the text qualifications that need to be handled. I thought about splitting on the ascii char, but i didn't know for sure what it its value is...
Good luck, it it comes even close, we can work.
ps: feel free to email me with a .prg file sample:
kitpackers@suddenlink.net
And, as for the "user-friendly", that always comes after the "cogs and gears" part - Model T's didn't sport electric windows. But again, that is all dependant on if anything at all works for you, then we can refine the interface to smooth things.


Report •

#9
March 7, 2013 at 01:33:42
This might get done with bat but i don't know what this means:

"BEGINNING WITH AND
INCLUDING the ASCII character and the $"

=====================
M2 Golden-Triangle


Report •

#10
March 7, 2013 at 04:06:04
Break files up on lines starting with "%". The "%" must be in the old file. At least that's how I read it.

How To Ask Questions The Smart Way


Report •

#11
March 7, 2013 at 08:55:36
Mechanix2Go and Razor2.3

This might get done with bat but i don't know what this means:

"BEGINNING WITH AND
INCLUDING the ASCII character and the $"

Break files up on lines starting with "%". The "%" must be in the old file. At least that's how I read it.

The following screen capture shows a completed output file, after being stripped from the long string of commands in the original file.

https://www.facebook.com/photo.php?...

A few comments UP, I posted links to my facebook page showing a sample ORIGINAL file...
What I am looking for is an easy utility to go into the original files that I have, strip one set of instructions from the string (as shown in this screen capture), create a NEW text document, insert this stripped set of instructions, and then name the NEW text document with the command name shown at the beginning of each string, including the .MIN extension. ---- ALL new text docs will have names ending in .MIN
I hope this better explains what I'm trying to accomplish!
Thanks for any help!
Dave


Report •

#12
March 7, 2013 at 23:31:42
Screen shots are useless. We need to know what's in the file.

ZIP it up and email it.

or put the ZIP here:

http://www.sendspace.com/

=====================
M2 Golden-Triangle


Report •

#13
March 8, 2013 at 06:49:25
CONGRATS TO "nbrane" FOR HIS PERFECT SOLUTION!

He and I have been working through direct email, so a lot of development testing isn't shown here, nor is the final scripting solution. But rest assured that "nbrane" came up with the PERFECT solution to my task requirements!

I can't thank him enough for his patience and dedication to providing me with this solution. He is a GREAT asset to this blog!

Thank you once again "nbrane"!!

Dave


Report •

Ask Question