LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 04-10-2013, 01:19 PM   #1
business_kid
Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware & Android
Posts: 6,180

Rep: Reputation: 527Reputation: 527Reputation: 527Reputation: 527Reputation: 527Reputation: 527
Scripting magic badly needed


I am trying to modify a file 85,000 lines long, so you'll understand why I don't want to do it manually. Kicad complains about the line numbers in bold because it can't draw them. Apologies for the length of this, but it's one component after the other, each with the same mistake.
Code:
#
# Dev Name: 7400FK
# Package Name: LCC20
# Dev Tech: ''
# Dev Prefix: IC
# Gate count = 5
#
DEF 7400FK IC 0 40 Y Y 5 L N
# Gate Name: A
# Symbol Name: 7400
F0 "IC" 100 125 50 H V L B
F1 "7400FK" 100 -200 50 H V L B
F2 "74xx-eu-LCC20" 0 150 50 H I C C
DRAW
P 2 1 0 0 -100 200 -100 -200
A -100 0 200 -899 899 1 1 0 N -100 -200 -100 200
X I0 2 -300 100 200 R 40 40 1 1 I
X I1 3 -300 -100 200 R 40 40 1 1 I
X O 4 300 0 200 L 40 40 1 1 O I
# Gate Name: B
# Symbol Name: 7400
P 2 2 0 0 -100 200 -100 -200
A -100 0 200 -899 899 2 1 0 N -100 -200 -100 200
X I0 6 -300 100 200 R 40 40 2 1 I 
X I1 8 -300 -100 200 R 40 40 2 1 I 
X O 9 300 0 200 L 40 40 2 1 O I
# Gate Name: C
# Symbol Name: 7400
P 2 3 0 0 -100 200 -100 -200
A -100 0 200 -899 899 3 1 0 N -100 -200 -100 200
X I0 13 -300 100 200 R 40 40 3 1 I
X I1 14 -300 -100 200 R 40 40 3 1 I 
X O 12 300 0 200 L 40 40 3 1 O I
# Gate Name: D
# Symbol Name: 7400
P 2 4 0 0 -100 200 -100 -200
A -100 0 200 -899 899 4 1 0 N -100 -200 -100 200
X I0 18 -300 100 200 R 40 40 4 1 I
X I1 19 -300 -100 200 R 40 40 4 1 I 
# Gate Name: P
# Symbol Name: PWRN
T 1 50 -155 50 0 5 0 GND
T 1 50 175 50 0 5 0 VCC
X GND 10 0 -300 200 U 40 40 5 1 W
X VCC 20 0 300 200 D 40 40 5 1 W
ENDDRAW
ENDDEF
What is below works - I've tested it. How the heck do I get it inserted automagically?

Code:
DEF 7400D IC 0 40 Y Y 5 L N
# Gate Name: A
# Symbol Name: 7400
F0 "IC" 100 125 50 H V L B
F1 "7400D" 100 -200 50 H V L B
F2 "74xx-eu-SO14" 0 150 50 H I C C
DRAW
P 2 1 0 0 -100 200 -100 -200
A -100 0 200 -899 899 1 1 0 N -100 -200 -100 200
X I0 1 -300 100 200 R 40 40 1 1 I
X I1 2 -300 -100 200 R 40 40 1 1 I
X O 3 300 0 200 L 40 40 1 1 O I
ENDDRAW
# Gate Name: B
# Symbol Name: 7400
DRAW
P 2 2 0 0 -100 200 -100 -200
A -100 0 200 -899 899 2 1 0 N -100 -200 -100 200
X I0 4 -300 100 200 R 40 40 2 1 I
X I1 5 -300 -100 200 R 40 40 2 1 I
X O 6 300 0 200 L 40 40 2 1 O I
ENDDRAW
# Gate Name: C
# Symbol Name: 7400
DRAW
P 2 3 0 0 -100 200 -100 -200
A -100 0 200 -899 899 3 1 0 N -100 -200 -100 200
X I0 9 -300 100 200 R 40 40 3 1 I
X I1 10 -300 -100 200 R 40 40 3 1 I
X O 8 300 0 200 L 40 40 3 1 O I
ENDDRAW
# Gate Name: D
# Symbol Name: 7400
DRAW
P 2 4 0 0 -100 200 -100 -200
A -100 0 200 -899 899 4 1 0 N -100 -200 -100 200
X I0 12 -300 100 200 R 40 40 4 1 I
X I1 13 -300 -100 200 R 40 40 4 1 I
X O 11 300 0 200 L 40 40 4 1 O I
ENDDRAW
# Gate Name: P
# Symbol Name: PWRN
DRAW
T 1 50 -155 50 0 5 0 GND
T 1 50 175 50 0 5 0 VCC
X GND 7 0 -300 200 U 40 40 5 1 W
X VCC 14 0 300 200 D 40 40 5 1 W
ENDDRAW
ENDDEF
Any ideas welcome. Changing back versions is not really an option. There are 2 very troublesome dependencies to compile for this, and the required options on the first are a mystery. So I end up compiling dependency 1, dependency 2 (which uses 1) and then kicad which barfs with an error related to dependency 1. It's an endless loop.
 
Old 04-10-2013, 01:49 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,990
Blog Entries: 54

Rep: Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743
sed -i "s|^.*Symbol.Name.*|\0\n# DRAW|g" -e "s|^.*Gate.*|# ENDDRAW\n\0|g" /path/to/file?
 
Old 04-10-2013, 01:49 PM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
Have a look at this:
Code:
sed -re 's/# Gate Name: ([B-Z])/ENDDRAW\n# Gate Name: \1/' -e 's/# Symbol Name: (.*)/# Symbol Name: \1\nDRAW/' infile
 
Old 04-11-2013, 04:36 AM   #4
business_kid
Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware & Android
Posts: 6,180

Original Poster
Rep: Reputation: 527Reputation: 527Reputation: 527Reputation: 527Reputation: 527Reputation: 527
Gentlemen, I am highly impressed! Thank you both for your attempts, which show more than a little intelligence and savvy. I couldn't follow either of them. I copied the file twice, and renamed them unspawn.lib and druuna.lib. UnSpawn's command returned
Quote:
bash-4.2$ sed -i "s|^.*Symbol.Name.*|\0\n# DRAW|g" -e "s|^.*Gate.*|# ENDDRAW\n\0|g" unspawn.lib
sed: can't read s|^.*Symbol.Name.*|\0\n# DRAW|g: No such file or directory
As I took it there was a typo, I left it there.

Druuna's command clogged stdout. So I reran as
Quote:
sed -re 's/# Gate Name: ([B-Z])/ENDDRAW\n# Gate Name: \1/' -e 's/# Symbol Name: (.*)/# Symbol Name: \1\nDRAW/' -i druuna.lib
And it was nearly perfect. Again, the Bold is undesired and should cause errors. Two draw commands without an 'enddraw' breaches syntax. If we got rid of the first one, that would be perfect. I would point out that there are sometimes more or no lines between the line beginning F1 and the first draw - user definition space. There's a web interface for creating devices, and it produces a different format to the supplied libs. Those F0 - F2 lines should not be drawn.

I hung the file (74xx-eu.lib) up here. It's 2.2mb and it allows a test of this.

Code:
# Dev Name: 7400D
# Package Name: SO14
# Dev Tech: ''
# Dev Prefix: IC
# Gate count = 5
#
DEF 7400D IC 0 40 Y Y 5 L N
# Gate Name: A
# Symbol Name: 7400
DRAW
F0 "IC" 100 125 50 H V L B
F1 "7400D" 100 -200 50 H V L B
F2 "74xx-eu-SO14" 0 150 50 H I C C
DRAW
P 2 1 0 0 -100 200 -100 -200
A -100 0 200 -899 899 1 1 0 N -100 -200 -100 200
X I0 1 -300 100 200 R 40 40 1 1 I 
X I1 2 -300 -100 200 R 40 40 1 1 I 
X O 3 300 0 200 L 40 40 1 1 O I
ENDDRAW
ENDDRAW
# Gate Name: B
# Symbol Name: 7400
DRAW
DRAW
P 2 2 0 0 -100 200 -100 -200
A -100 0 200 -899 899 2 1 0 N -100 -200 -100 200
X I0 4 -300 100 200 R 40 40 2 1 I 
X I1 5 -300 -100 200 R 40 40 2 1 I 
X O 6 300 0 200 L 40 40 2 1 O I
ENDDRAW
# Gate Name: C
# Symbol Name: 7400
DRAW
DRAW
P 2 3 0 0 -100 200 -100 -200
A -100 0 200 -899 899 3 1 0 N -100 -200 -100 200
X I0 9 -300 100 200 R 40 40 3 1 I 
X I1 10 -300 -100 200 R 40 40 3 1 I 
X O 8 300 0 200 L 40 40 3 1 O I
ENDDRAW
# Gate Name: D
# Symbol Name: 7400
DRAW
P 2 4 0 0 -100 200 -100 -200
A -100 0 200 -899 899 4 1 0 N -100 -200 -100 200
X I0 12 -300 100 200 R 40 40 4 1 I 
X I1 13 -300 -100 200 R 40 40 4 1 I 
X O 11 300 0 200 L 40 40 4 1 O I
ENDDRAW
# Gate Name: P
# Symbol Name: PWRN
DRAW
T 1 50 -155 50 0 5 0 GND
T 1 50 175 50 0 5 0 VCC
X GND 7 0 -300 200 U 40 40 5 1 W 
X VCC 14 0 300 200 D 40 40 5 1 W 
ENDDRAW
ENDDEF
FWIW, I have Slackware-14.0. bash-4.2$ sed --version returns "GNU sed version 4.2.1".
 
Old 04-11-2013, 05:13 AM   #5
pan64
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,499

Rep: Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221
probably this:
awk ' /# Gate Name:/ { print "ENDDRAW" } { print $0 } /# Symbol Name/ { print "DRAW" } ' test.txt
 
Old 04-11-2013, 05:23 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
A little tinkering with my original solution:
Code:
sed -re 's/# Gate Name: ([B-Z])/ENDDRAW\n# Gate Name: \1/' -e '20,$s/# Symbol Name: (.*)/# Symbol Name: \1\nDRAW/' infile > outfile
Results in (using your original example in post #1):
Code:
#
# Dev Name: 7400FK
# Package Name: LCC20
# Dev Tech: ''
# Dev Prefix: IC
# Gate count = 5
#
DEF 7400FK IC 0 40 Y Y 5 L N
# Gate Name: A
# Symbol Name: 7400      This time not followed by DRAW
F0 "IC" 100 125 50 H V L B
F1 "7400FK" 100 -200 50 H V L B
F2 "74xx-eu-LCC20" 0 150 50 H I C C
DRAW
P 2 1 0 0 -100 200 -100 -200
A -100 0 200 -899 899 1 1 0 N -100 -200 -100 200
X I0 2 -300 100 200 R 40 40 1 1 I
X I1 3 -300 -100 200 R 40 40 1 1 I
X O 4 300 0 200 L 40 40 1 1 O I
ENDDRAW
# Gate Name: B
# Symbol Name: 7400
DRAW
P 2 2 0 0 -100 200 -100 -200
A -100 0 200 -899 899 2 1 0 N -100 -200 -100 200
X I0 6 -300 100 200 R 40 40 2 1 I 
X I1 8 -300 -100 200 R 40 40 2 1 I 
X O 9 300 0 200 L 40 40 2 1 O I
ENDDRAW
# Gate Name: C
# Symbol Name: 7400
DRAW
P 2 3 0 0 -100 200 -100 -200
A -100 0 200 -899 899 3 1 0 N -100 -200 -100 200
X I0 13 -300 100 200 R 40 40 3 1 I
X I1 14 -300 -100 200 R 40 40 3 1 I 
X O 12 300 0 200 L 40 40 3 1 O I
ENDDRAW
# Gate Name: D
# Symbol Name: 7400
DRAW
P 2 4 0 0 -100 200 -100 -200
A -100 0 200 -899 899 4 1 0 N -100 -200 -100 200
X I0 18 -300 100 200 R 40 40 4 1 I
X I1 19 -300 -100 200 R 40 40 4 1 I 
ENDDRAW
# Gate Name: P
# Symbol Name: PWRN
DRAW
T 1 50 -155 50 0 5 0 GND
T 1 50 175 50 0 5 0 VCC
X GND 10 0 -300 200 U 40 40 5 1 W
X VCC 20 0 300 200 D 40 40 5 1 W
ENDDRAW
ENDDEF
 
1 members found this post helpful.
Old 04-11-2013, 06:52 AM   #7
business_kid
Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware & Android
Posts: 6,180

Original Poster
Rep: Reputation: 527Reputation: 527Reputation: 527Reputation: 527Reputation: 527Reputation: 527
I'll try today's work in a second, and post again.

@UnSpawn: Your command did process the file, and inserted the ENDDRAW commands in the right place AFAICT. No Draw commands. Only pedantic interpreters would puke on a second ENDDRAW. There are extra ones, but that's because I ran the command more than once.

Code:
# Dev Name: 7400D
# Package Name: SO14
# Dev Tech: ''
# Dev Prefix: IC
# ENDDRAW
# ENDDRAW
# Gate count = 5
#
DEF 7400D IC 0 40 Y Y 5 L N
# ENDDRAW
# ENDDRAW
# Gate Name: A
# Symbol Name: 7400
F0 "IC" 100 125 50 H V L B
F1 "7400D" 100 -200 50 H V L B
F2 "74xx-eu-SO14" 0 150 50 H I C C
DRAW
P 2 1 0 0 -100 200 -100 -200
A -100 0 200 -899 899 1 1 0 N -100 -200 -100 200
X I0 1 -300 100 200 R 40 40 1 1 I 
X I1 2 -300 -100 200 R 40 40 1 1 I 
X O 3 300 0 200 L 40 40 1 1 O I
ENDDRAW
# ENDDRAW
# ENDDRAW
# Gate Name: B
# Symbol Name: 7400
DRAW
P 2 2 0 0 -100 200 -100 -200
A -100 0 200 -899 899 2 1 0 N -100 -200 -100 200
X I0 4 -300 100 200 R 40 40 2 1 I 
X I1 5 -300 -100 200 R 40 40 2 1 I 
X O 6 300 0 200 L 40 40 2 1 O I
ENDDRAW
# ENDDRAW
# ENDDRAW
# Gate Name: C
# Symbol Name: 7400
DRAW
P 2 3 0 0 -100 200 -100 -200
A -100 0 200 -899 899 3 1 0 N -100 -200 -100 200
X I0 9 -300 100 200 R 40 40 3 1 I 
X I1 10 -300 -100 200 R 40 40 3 1 I 
X O 8 300 0 200 L 40 40 3 1 O I
# ENDDRAW
# ENDDRAW
# Gate Name: D
# Symbol Name: 7400
P 2 4 0 0 -100 200 -100 -200
A -100 0 200 -899 899 4 1 0 N -100 -200 -100 200
X I0 12 -300 100 200 R 40 40 4 1 I 
X I1 13 -300 -100 200 R 40 40 4 1 I 
X O 11 300 0 200 L 40 40 4 1 O I
# ENDDRAW
# ENDDRAW
# Gate Name: P
# Symbol Name: PWRN
T 1 50 -155 50 0 5 0 GND
T 1 50 175 50 0 5 0 VCC
X GND 7 0 -300 200 U 40 40 5 1 W 
X VCC 14 0 300 200 D 40 40 5 1 W 
ENDDRAW
ENDDEF

#
# Dev Name: 7400FK
# Package Name: LCC20
# Dev Tech: ''
# Dev Prefix: IC
# ENDDRAW
# ENDDRAW
# Gate count = 5
#
DEF 7400FK IC 0 40 Y Y 5 L N
# ENDDRAW
# ENDDRAW
# Gate Name: A
# Symbol Name: 7400
F0 "IC" 100 125 50 H V L B
F1 "7400FK" 100 -200 50 H V L B
F2 "74xx-eu-LCC20" 0 150 50 H I C C
DRAW
P 2 1 0 0 -100 200 -100 -200
A -100 0 200 -899 899 1 1 0 N -100 -200 -100 200
X I0 2 -300 100 200 R 40 40 1 1 I 
X I1 3 -300 -100 200 R 40 40 1 1 I 
X O 4 300 0 200 L 40 40 1 1 O I
# ENDDRAW
# ENDDRAW
# Gate Name: B
# Symbol Name: 7400
P 2 2 0 0 -100 200 -100 -200
A -100 0 200 -899 899 2 1 0 N -100 -200 -100 200
X I0 6 -300 100 200 R 40 40 2 1 I 
X I1 8 -300 -100 200 R 40 40 2 1 I 
X O 9 300 0 200 L 40 40 2 1 O I
# ENDDRAW
# ENDDRAW
# Gate Name: C
# Symbol Name: 7400
P 2 3 0 0 -100 200 -100 -200
A -100 0 200 -899 899 3 1 0 N -100 -200 -100 200
X I0 13 -300 100 200 R 40 40 3 1 I 
X I1 14 -300 -100 200 R 40 40 3 1 I 
X O 12 300 0 200 L 40 40 3 1 O I
# ENDDRAW
# ENDDRAW
# Gate Name: D
# Symbol Name: 7400
P 2 4 0 0 -100 200 -100 -200
A -100 0 200 -899 899 4 1 0 N -100 -200 -100 200
X I0 18 -300 100 200 R 40 40 4 1 I 
X I1 19 -300 -100 200 R 40 40 4 1 I 
X O 16 300 0 200 L 40 40 4 1 O I
# ENDDRAW
# ENDDRAW
# Gate Name: P
# Symbol Name: PWRN
T 1 50 -155 50 0 5 0 GND
T 1 50 175 50 0 5 0 VCC
X GND 10 0 -300 200 U 40 40 5 1 W 
X VCC 20 0 300 200 D 40 40 5 1 W 
ENDDRAW
ENDDEF

Last edited by business_kid; 04-11-2013 at 06:55 AM.
 
Old 04-11-2013, 08:00 AM   #8
business_kid
Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware & Android
Posts: 6,180

Original Poster
Rep: Reputation: 527Reputation: 527Reputation: 527Reputation: 527Reputation: 527Reputation: 527
@pan64: Thank you I had thought of awk, but I have suffering enough with this. Your command inserted too many DRAW & ENDDRAW commands, as you see, the bold entries will cause it to puke. The file is 85000 lines long, one definition after another. I marked a split below.

Code:
DRAW
T 1 50 -155 50 0 5 0 GND
T 1 50 175 50 0 5 0 VCC
X GND 7 0 -300 200 U 40 40 5 1 W 
X VCC 14 0 300 200 D 40 40 5 1 W 
ENDDRAW
ENDDEF
***Comment: end of last device***

#
# Dev Name: 7400FK
# Package Name: LCC20
# Dev Tech: ''
# Dev Prefix: IC
# Gate count = 5
#
DEF 7400FK IC 0 40 Y Y 5 L N
ENDDRAW
# Gate Name: A
# Symbol Name: 7400
DRAW
F0 "IC" 100 125 50 H V L B
F1 "7400FK" 100 -200 50 H V L B
F2 "74xx-eu-LCC20" 0 150 50 H I C C
DRAW
P 2 1 0 0 -100 200 -100 -200
A -100 0 200 -899 899 1 1 0 N -100 -200 -100 200
X I0 2 -300 100 200 R 40 40 1 1 I 
X I1 3 -300 -100 200 R 40 40 1 1 I
The rest of the entry is alters flawlessly :-).

@Druuna: PERFECT File is converted. Thank you kindly.
EDIT: Actually, not perfect, just nearly perfect. I got errors every 50 lines or so of this nature
Code:
#
DEF 74148FK IC 0 40 Y Y 2 L N
# Gate Name: A
# Symbol Name: 74148
DRAW
F0 "IC" -300 525 50 H V L B
F1 "74148FK" -300 -700 50 H V L B
F2 "74xx-eu-LCC20" 0 150 50 H I C C
DRAW
P 2 1 0 0 -300 -600 300 -600
P 2 1 0 0 300 -600 300 500
P 2 1 0 0 300 500 -300 500
P 2 1 0 0 -300 500 -300 -600
X 0 13 -500 400 200 R 40 40 1 1 I I
X 1 14 -500 300 200 R 40 40 1 1 I I
With component definitions of 15-25 lines generally, That's every second or third component, and about 1500 errors - a lot to correct by hand. Sod's Law definitely applies! I checked the original file, (which is eagle's components converted) and the original is good.

Last edited by business_kid; 04-11-2013 at 08:31 AM. Reason: Not Solved.
 
Old 04-11-2013, 09:21 AM   #9
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
I've had a better look at the example you posted and you do need some additional tweaks to get it working (100%??)

This is getting ugly, but it seems to do the trick for as far as I can tell:
Code:
# split for better readability
sed -re '35,$s/# Gate Name: ([B-Z])/ENDDRAW\n# Gate Name: \1/' \
     -e '35,${/DEF /,/F0 /!s/# Symbol Name: (.*)/# Symbol Name: \1\nDRAW/}' infile > outfile

# as a one-liner
sed -re '35,$s/# Gate Name: ([B-Z])/ENDDRAW\n# Gate Name: \1/' -e '35,${/DEF /,/F0 /!s/# Symbol Name: (.*)/# Symbol Name: \1\nDRAW/}' infile > outfile
Output example of the first block:
Code:
EESchema-LIBRARY Version 2.3  29/04/2008-12:21:03
# Converted with eagle2kicad.ulp Version 0.9
# Device count = 1807
#
# Dev Name: 7400D
# Package Name: SO14
# Dev Tech: ''
# Dev Prefix: IC
# Gate count = 5
#
DEF 7400D IC 0 40 Y Y 5 L N
# Gate Name: A
# Symbol Name: 7400
F0 "IC" 100 125 50 H V L B
F1 "7400D" 100 -200 50 H V L B
F2 "74xx-eu-SO14" 0 150 50 H I C C
DRAW
P 2 1 0 0 -100 200 -100 -200
A -100 0 200 -899 899 1 1 0 N -100 -200 -100 200
X I0 1 -300 100 200 R 40 40 1 1 I
X I1 2 -300 -100 200 R 40 40 1 1 I
X O 3 300 0 200 L 40 40 1 1 O I
ENDDRAW
# Gate Name: B
# Symbol Name: 7400
DRAW
P 2 2 0 0 -100 200 -100 -200
A -100 0 200 -899 899 2 1 0 N -100 -200 -100 200
X I0 4 -300 100 200 R 40 40 2 1 I
X I1 5 -300 -100 200 R 40 40 2 1 I
X O 6 300 0 200 L 40 40 2 1 O I
ENDDRAW
# Gate Name: C
# Symbol Name: 7400
DRAW
P 2 3 0 0 -100 200 -100 -200
A -100 0 200 -899 899 3 1 0 N -100 -200 -100 200
X I0 9 -300 100 200 R 40 40 3 1 I
X I1 10 -300 -100 200 R 40 40 3 1 I
X O 8 300 0 200 L 40 40 3 1 O I
ENDDRAW
# Gate Name: D
# Symbol Name: 7400
DRAW
P 2 4 0 0 -100 200 -100 -200
A -100 0 200 -899 899 4 1 0 N -100 -200 -100 200
X I0 12 -300 100 200 R 40 40 4 1 I
X I1 13 -300 -100 200 R 40 40 4 1 I
X O 11 300 0 200 L 40 40 4 1 O I
ENDDRAW
# Gate Name: P
# Symbol Name: PWRN
DRAW
T 1 50 -155 50 0 5 0 GND
T 1 50 175 50 0 5 0 VCC
X GND 7 0 -300 200 U 40 40 5 1 W
X VCC 14 0 300 200 D 40 40 5 1 W
ENDDRAW
ENDDEF
Output example of the last issue you posted:
Code:
#
# Dev Name: 74148D
# Package Name: SO16
# Dev Tech: ''
# Dev Prefix: IC
# Gate count = 2
#
DEF 74148D IC 0 40 Y Y 2 L N
# Gate Name: A
# Symbol Name: 74148
F0 "IC" -300 525 50 H V L B
F1 "74148D" -300 -700 50 H V L B
F2 "74xx-eu-SO16" 0 150 50 H I C C
DRAW
P 2 1 0 0 -300 -600 300 -600
P 2 1 0 0 300 -600 300 500
P 2 1 0 0 300 500 -300 500
P 2 1 0 0 -300 500 -300 -600
X 0 10 -500 400 200 R 40 40 1 1 I I
X 1 11 -500 300 200 R 40 40 1 1 I I
X 2 12 -500 200 200 R 40 40 1 1 I I
X 3 13 -500 100 200 R 40 40 1 1 I I
X 4 1 -500 0 200 R 40 40 1 1 I I
X 5 2 -500 -100 200 R 40 40 1 1 I I
X 6 3 -500 -200 200 R 40 40 1 1 I I
X 7 4 -500 -300 200 R 40 40 1 1 I I
X A0 9 500 400 200 L 40 40 1 1 O I
X A1 7 500 300 200 L 40 40 1 1 O I
X A2 6 500 200 200 L 40 40 1 1 O I
X EI 5 -500 -500 200 R 40 40 1 1 I I
X EO 15 500 -500 200 L 40 40 1 1 O
X GS 14 500 -400 200 L 40 40 1 1 O I
ENDDRAW
# Gate Name: P
# Symbol Name: PWRN
DRAW
T 1 50 -155 50 0 2 0 GND
T 1 50 175 50 0 2 0 VCC
X GND 8 0 -300 200 U 40 40 2 1 W
X VCC 16 0 300 200 D 40 40 2 1 W
ENDDRAW
ENDDEF
 
1 members found this post helpful.
Old 04-11-2013, 02:26 PM   #10
business_kid
Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware & Android
Posts: 6,180

Original Poster
Rep: Reputation: 527Reputation: 527Reputation: 527Reputation: 527Reputation: 527Reputation: 527
@Druuna:

You're on the ball this time. Perfect. Thank you for the effort and willingness to help on this.

I can't test it definitively, because I made the mistake of letting F-18 update, and it's all over the place again.(watch for flame throwers :-). That's my universal experience with F-18. It was nagging me about important updates but I'm unable to boot it atm. That's important all right :-P. It looks like an error in an update to me,
http://www.linuxquestions.org/questi...te-4175457817/

but it just could be a kernel command line.

I spent 2 days doctoring and debugging an extra library of the parts in my design, and a 48pin chip I have to add to them, and I found someone had done some of it already :-/.
 
Old 04-11-2013, 05:51 PM   #11
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946
Just to be clear, you need to bracket all instances of "Gate Name" and "Symbol Name" except for the first one? And the lines are always paired?

How about this?
Code:
sed -e '1,/^# Symbol Name/b; -e '/^# Gate Name/i ENDDRAW' -e '/^# Symbol Name/a DRAW' infile
It ignores (branches to the end) every line up to and including the first 'Symbol Name', then simply inserts/appends on every matching pattern after that.

A similar modification could probably be done with pan64's awk command.


Another, probably easier, option would be to simply bracket all lines, then go back and re-edit the file again to remove them from entry A.
 
Old 04-11-2013, 07:47 PM   #12
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 3,379

Rep: Reputation: 824Reputation: 824Reputation: 824Reputation: 824Reputation: 824Reputation: 824Reputation: 824
Quote:
Just to be clear, you need to bracket all instances of "Gate Name" and "Symbol Name" except for the first one? And the lines are always paired?
I do not read the problem that way.
What is required is:
1. a DRAW command is inserted either after a line starting "# Symbol Name" if the next line does not start with F
or
after the last line starting with F following a line starting "# Symbol Name".
2. an ENDDRAW command is inserted after the last line starting with X in a block starting with a line "# Symbol Name".

I think a scripting solution is required.
 
Old 04-11-2013, 09:04 PM   #13
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,232

Rep: Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024
Agreed. I am impressed by the sed skills, but given the warning about differing formats in post #4, I think a programming soln would be more flexible.
 
Old 04-11-2013, 11:12 PM   #14
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 3,379

Rep: Reputation: 824Reputation: 824Reputation: 824Reputation: 824Reputation: 824Reputation: 824Reputation: 824
My attempt at a bash solution.
Code:
#!/bin/bash

file=$1
need_draw=false
need_enddraw=false

while read line ;  do
  if [[ ${line:0:13} == "# Symbol Name" ]]; then
    need_draw=true;
    need_enddraw=true;
  elif [[ ${line:0:11} == "# Gate Name" ]] && $need_enddraw; then
    echo "ENDDRAW";
    need_enddraw=false;
  elif [[ ${line:0:4} == "DRAW" ]] && $need_draw; then
    need_draw=false;
  elif [[ ${line:0:1} != "F" ]] && $need_draw; then
    echo "DRAW";
    need_draw=false;
  fi
  echo "$line";
done < $file
 
Old 04-12-2013, 09:20 AM   #15
business_kid
Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware & Android
Posts: 6,180

Original Poster
Rep: Reputation: 527Reputation: 527Reputation: 527Reputation: 527Reputation: 527Reputation: 527
In answer to the queries: I read the problem as (a) adding an ENDDRAW before a gate name _while_inside_ a draw instruction, and then (b) adding a DRAW after the Symbol name provided (a) has happened. Gate A should never be altered.

The background is that there is about 1000 basic 74xx parts, but these are continually remarketed in new technologies and different packages. A 7400, for instance, can be 7400, or [W]74X[Y]00[Z], where
W = a manufacturer prefix - each manufacturer chooses his own unique one, but also borrows others
X = technology. LS, HC, S, F, AC, HV, LV, AUC, etc. At least a dozen technology permutations exist, and more are continually developed
Y = A refinement, flavour, or spin of the technology. (e.g hc, hct)
Z = A package suffix. The 74AUC uses tiny packaging unique to it atm, AFAICT.

The package bit is hugely important as schematics transfer to PCB layout where the package size is critical. In the old days weeks used to be lost doing this manually. Now weeks are lost setting up cad programs to do it automatically :-/.

The 85000 line file is Here On My Skydrive. It's 2.2Mb

@Allend: I copied that file to allend.lib and ran it as you see. Hope that was right.
Code:
bash-4.2$ ./allend.sh allend.lib
./allend.sh: line 8: conditional binary operator expected
./allend.sh: line 8: syntax error near `Name"'
./allend.sh: line 8: `  if [[  == "# Symbol Name" ]]; then'
bash-4.2$ cat allend.lib | ./allend.sh -
./allend.sh: line 8: conditional binary operator expected
./allend.sh: line 8: syntax error near `Name"'
./allend.sh: line 8: `  if [[  == "# Symbol Name" ]]; then'
I repeat, this is 85,000 lines long - one definition after the other. Your script seems to think of one definition per file, to the extent that I grasp it.

@David_The_H:
Just to be clear, you need to bracket all instances of "Gate Name" and "Symbol Name" except for the first one? And the lines are always paired?

Yes. They don't always exist, but in a device with many gates the eagle --> kicad converter left them there.There is always a power gate at the end. No good news, I'm afraid. When i tried your sed (copy 'n' paste) I got
Code:
sed -e '1,/^# Symbol Name/b; -e '/^# Gate Name/i ENDDRAW' -e '/^# Symbol Name/a DRAW' 74xx-eu.lib > DavidTheH.lib
>
I did try to fix the commas, but I didn't hit on it, and felt a bit like the sorcerer's apprentice, so I quit before I did damage.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Sound help badly needed LinuxBlackBox Linux - Software 3 10-24-2007 04:55 AM
badly needed your help kasmot Linux - Software 3 02-02-2006 10:02 PM
Hardware help needed.. badly jihadcman Fedora 2 06-21-2004 06:28 AM
tar.gz help badly needed headshot Linux - Newbie 9 07-25-2003 02:53 PM
bpbatch help badly needed? m1anh Linux - General 2 02-07-2003 05:55 PM


All times are GMT -5. The time now is 05:41 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration