FAQ | Search | Memberlist | Usergroups | Register | Profile | Inbox | Log in | SmartFeedSmartFeed


 okgg.org > Forum Index > All Things Technical > text parsing?

  Author    Thread Post new topic  Reply to topic
Souper Phly
Junkie


Joined: 05 Jan 2004
Posts: 672
Location: OKC
text parsing?  Reply with quote  

We have several cnc mills that we need to backup the programs on. The problem is that the mills use basic serial communication and when you tell it to send all programs it sends them all as one long text file. I would like to find a script or parsing program to go through this file and break it into individual files with the "program name".nc type format with a % added to the start and end of the file.
like this

long text file.nc
o05050
g123 m23 g234
g222 m222 g44
o05150
g888 m22 g333
m222 g333 m444
o05250
g123 m23 g234
g222 m222 g44

output
o05050.nc
%
g123 m23 g234
g222 m222 g44
%

o05150.nc
%
g888 m22 g333
m222 g333 m444
%
and so on the letter o appears only at the start of program names and nowhere in the program codes so at the moment we are doing a crtl-f cut/paste thing but there has got to be a better way. any ideas?
_________________
The two most common elements in the universe are Hydrogen and stupidity.
Harlan Ellison

Post Thu Oct 30, 2008 9:23 pm  View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number
detox
Naaaaaah. NaaaaaFLAC.


Joined: 20 Mar 2003
Posts: 4317
Location: Durant
 Reply with quote  

could probably ask someone in an entry level C++ or Java class to write a simple parser

C# help: http://www.codeproject.com/KB/files/BSTextParser.aspx
_________________
I7 2600K
EVGA 980ti FTW
16gigs
SSD
3x Dell U2412 Monitors

Post Fri Oct 31, 2008 12:33 am  View user's profile Send private message Visit poster's website ICQ Number
LightningCrash
Smile like Bob, order your free LC today


Joined: 03 Apr 2003
Posts: 5020
 Reply with quote  

here

parsecnc.py

Code


import os, sys

cncfile=open(sys.argv[1],'r')
f=cncfile.read()
f=f.splitlines()

def dumpprog(line,filename):
    wri = open(filename,'a')
    line=line + '\n'
    wri.write(line)
   
w='defaultoutput.nc'

while len(f)>0:
        line = f.pop(0)
        if line.find('o')==0:
            dumpprog('%',w)
            w=line + '.nc'
            dumpprog('%',w)
            line=[]
        if len(line)>0: dumpprog(line,w)
dumpprog('%',w)


Usage: python parsecnc.py filename

Example

$mkdir ~/tmp2929
$cd ~/tmp2929
$python ~/workspace/souperparser/src/parsecnc.py ~/cnctest
$ls
o05050.nc o05150.nc o05250.nc defaultoutput.nc
$cat o05050.nc
%
g123 m23 g234
g222 m222 g44
%

Post Fri Oct 31, 2008 8:27 am  View user's profile Send private message
LightningCrash
Smile like Bob, order your free LC today


Joined: 03 Apr 2003
Posts: 5020
 Reply with quote  

Did this work for you?

Post Fri Nov 07, 2008 10:06 am  View user's profile Send private message
Souper Phly
Junkie


Joined: 05 Jan 2004
Posts: 672
Location: OKC
 Reply with quote  

sorry I hadn't replied on this unfortunatly I'm still waiting for IT to give me enough access to install python, but playing with it at home it seems to be working. I'll let you know if/when I hear from IT on it. thanks for your help LC
_________________
The two most common elements in the universe are Hydrogen and stupidity.
Harlan Ellison

Post Fri Nov 07, 2008 1:48 pm  View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number
LightningCrash
Smile like Bob, order your free LC today


Joined: 03 Apr 2003
Posts: 5020
 Reply with quote  

Let me know what you find out. I can quickly change something if need be.

Python is most excellent.

Post Fri Nov 07, 2008 2:37 pm  View user's profile Send private message
LightningCrash
Smile like Bob, order your free LC today


Joined: 03 Apr 2003
Posts: 5020
 Reply with quote  

What ever happened with this?

Post Wed Oct 14, 2009 3:47 pm  View user's profile Send private message
LightningCrash
Smile like Bob, order your free LC today


Joined: 03 Apr 2003
Posts: 5020
 Reply with quote  

Sad

we miss you

Post Tue Nov 03, 2009 11:45 am  View user's profile Send private message
LightningCrash
Smile like Bob, order your free LC today


Joined: 03 Apr 2003
Posts: 5020
 Reply with quote  

Soup, how did this ever play out?

Post Wed May 05, 2010 9:40 am  View user's profile Send private message
Souper Phly
Junkie


Joined: 05 Jan 2004
Posts: 672
Location: OKC
 Reply with quote  

Funny story that was. IT said no, so there I am sitting in the office doing it by hand for the third day and the boss walks in and asks what I'm doing. I'm really sick of staring at my laptop so I sorta went off while telling him. He says there ought to be a program that can do that. I said there is but IT won't let me install it. He says fuck that email it to them and let them do it. I don't know if they ever got something to parse the files but I would imagine they did as this is a monthly ritual and we add several programs a month.
_________________
The two most common elements in the universe are Hydrogen and stupidity.
Harlan Ellison

Post Wed May 05, 2010 7:57 pm  View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number
  Display posts from previous:      
Post new topic  Reply to topic

Last Thread | Next Thread  >

Quick Reply

  
Jump to:  
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum