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:
# Code:
DEF 7400D IC 0 40 Y Y 5 L N |
sed -i "s|^.*Symbol.Name.*|\0\n# DRAW|g" -e "s|^.*Gate.*|# ENDDRAW\n\0|g" /path/to/file?
|
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 |
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:
Druuna's command clogged stdout. So I reran as Quote:
I hung the file (74xx-eu.lib) up here. It's 2.2mb and it allows a test of this. Code:
# Dev Name: 7400D |
probably this:
awk ' /# Gate Name:/ { print "ENDDRAW" } { print $0 } /# Symbol Name/ { print "DRAW" } ' test.txt |
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 Code:
# |
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 |
@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 @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:
# |
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 Code:
EESchema-LIBRARY Version 2.3 29/04/2008-12:21:03 Code:
# |
@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 :-/. |
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 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. |
Quote:
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. |
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.
|
My attempt at a bash solution.
Code:
#!/bin/bash |
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 @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 |
All times are GMT -5. The time now is 11:59 PM. |