LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-12-2008, 01:01 PM   #1
gary_in_springhill
Member
 
Registered: Mar 2008
Posts: 136

Rep: Reputation: 21
command to pen optimize hpgl file


CorelDraw (wine) has a pretty basic hpgl export filter. It does not do optomizing for pen colors. Via script/sed I have auto-edited the output for my machine thats works perfect except I need the pens grouped so I figure something to cut and paste using variables $SP7 (pen #7) and $LT (a known point to end cut). The file will ALWAYS will only be SP3 and SP7 (pen 3 and pen 7).

Then paste the SP7 snips to the end of the file so all pen 3 command are in a consecutive order then follwed by pen 7. Below is a sample of corel output. This is a very small and simple file, the working files are much bigger. Maybe 25 times bigger.

IN;
VS32,1;
VS32,2;
VS32,3;
VS32,4;
VS32,5;
VS32,6;
VS32,7;
VS32,8;
WU0;
PW0.349,1;
PW0.349,2;
PW0.349,3;
PW0.349,4;
PW0.349,5;
PW0.349,6;
PW0.349,7;
PW0.349,8;
SP7; I need file snipped here at Sp7 (including "SP7
LT;
PU20932 6924;
PD21275 6936;
PD21592 6972;
PD21882 7030;
PD22133 7104;
PD22341 7198;
PD22425 7249;
PD22496 7302;
PD22555 7358;
PD22595 7419;
PD22623 7480;
PD22631 7543;
PD22623 7607;
PD22595 7668;
PD22555 7726;
PD22496 7785;
PD22425 7838;
PD22341 7889;
PD22133 7980;
PD21882 8056;
PD21592 8112;
PD21275 8150;
PD20932 8163;
PD20591 8150;
PD20271 8112;
PD19984 8056;
PD19733 7980;
PD19524 7889;
PD19438 7838;
PD19367 7785;
PD19311 7726;
PD19268 7668;
PD19243 7607;
PD19235 7543;
PD19243 7480;
PD19268 7419;
PD19311 7358;
PD19367 7302;
PD19438 7249;
PD19524 7198;
PD19733 7104;
PD19984 7030;
PD20271 6972;
PD20591 6936;
PD20932 6924; Snip stops here using SP3 as the noninclusive end point
SP3;
LT;
PU12120 5803;
PD14719 5803;
PD14719 9801;
PD12120 9801;
PD12120 5803;
LT;
PU7726 13035;
PD9525 13035;
PD9525 15755;
PD7726 15755;
PD7726 13035;
SP7; Another snip starts here
LT;
PU8183 6164;
PD8280 6174;
PD8374 6205;
PD8463 6256;
PD8549 6324;
PD8630 6410;
PD8709 6512;
PD8780 6629;
PD8849 6761;
PD8910 6906;
PD8963 7063;
PD9011 7231;
PD9050 7409;
PD9083 7597;
PD9105 7792;
PD9118 7995;
PD9123 8201;
PD9118 8409;
PD9105 8613;
PD9083 8808;
PD9050 8994;
PD9011 9171;
PD8963 9342;
PD8910 9497;
PD8849 9641;
PD8780 9773;
PD8709 9893;
PD8630 9994;
PD8549 10078;
PD8463 10147;
PD8374 10198;
PD8280 10228;
PD8183 10238;
PD8089 10228;
PD7995 10198;
PD7907 10147;
PD7820 10078;
PD7736 9994;
PD7660 9893;
PD7586 9773;
PD7520 9641;
PD7459 9497;
PD7406 9342;
PD7358 9171;
PD7320 8994;
PD7287 8808;
PD7264 8613;
PD7251 8409;
PD7246 8201;
PD7251 7995;
PD7264 7792;
PD7287 7597;
PD7320 7409;
PD7358 7231;
PD7406 7063;
PD7459 6906;
PD7520 6761;
PD7586 6629;
PD7660 6512;
PD7736 6410;
PD7820 6324;
PD7907 6256;
PD7995 6205;
PD8089 6174;
PD8183 6164;
LT;
PU3848 11798;
PD6606 11798;
PD6606 15194;
PD3848 15194;
PD3848 11798; ends here
SP0;

Then all the SP& snips get put here at end of file, the order isn't import where which snip goes first
just as long as all the SP7 segments are at the end.

I sure hope someone can help me I've been three days on this task with sed/ed it's so darn hard when scripts are new to you!!

Thanks
Gary
 
Old 03-12-2008, 05:59 PM   #2
PatrickNew
Senior Member
 
Registered: Jan 2006
Location: Charleston, SC, USA
Distribution: Debian, Gentoo, Ubuntu, RHEL
Posts: 1,148
Blog Entries: 1

Rep: Reputation: 48
How about this? It works on my machine. If you run this with any non-GNU sed, then the -r option on that first sed should be switched to a -E.
Code:
#!/bin/sh
TMP_FILE=`mktemp`
cat srcFile | tr -d '\n' | sed -r -e 's/SP[0-9]+;/\n&/g' > $TMP_FILE
grep -v -e "SP7;" $TMP_FILE > destFile
grep -e "SP7" $TMP_FILE >> destFile
cat destFile | tr -d '\n' | sed 's/;/;\n/g' > $TMP_FILE
mv -f $TMP_FILE destFile
 
Old 03-13-2008, 03:23 AM   #3
angrybanana
Member
 
Registered: Oct 2003
Distribution: Archlinux
Posts: 147

Rep: Reputation: 21
awk solution
Code:
awk '{if(l=="SP7;") {a[i++]=l$0} else {print l$0} l=RT} 
END{print RT;for(i in a){print a[i]}}' RS='SP[0-9];' ORS='' penfile
 
Old 03-13-2008, 07:15 AM   #4
gary_in_springhill
Member
 
Registered: Mar 2008
Posts: 136

Original Poster
Rep: Reputation: 21
Got it !

Thanks for all your help!
4 16/hr days and many pots of coffee I know have a very nice kde gui driver/inteface for my 3 engravers.
This was my first attempt at complex scripting (complex for me) and I learned so much this last problem was way to complex for me, but man it works like a charm!!

Thanks again!

Now it's backup to tape and nap time!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
boot from any .iso file on a USB pen drive browny_amiga Linux - General 10 04-07-2008 04:44 PM
LXer: Linux ext3 Filesystem" Optimize Directories / File Access Time LXer Syndicated Linux News 0 02-01-2008 09:10 AM
Copy file from pen drive to disk deostroll Linux - Desktop 7 01-05-2008 09:49 AM
unable to change pen drive file permission linuxmandrake Ubuntu 2 08-29-2006 12:12 PM
Mounting usb pen drive file permssions problems linuxmandrake Debian 1 10-10-2005 07:21 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration