[ale] [OT] sed/php/bash-script programming question

jonathan glass (ibb) jonathan.glass at ibb.gatech.edu
Sun Oct 27 11:07:13 EST 2002


I'm trying to parse an HTML form on the server, and create tables
dynamically based on the content of the <input items in the form. (I'm
trying to automate some of the backend work I have to do at every
Student Government election.

So, having been out of the programming saddle for 6 months, I'm trying
to hack this together...

I placed the following command (ugly, I know) in a shell script to parse
all the input names...

echo "CREATE TABLE GKVoteRESULTS ("
grep "<input" ballot.html \
| sed s/"[<|>]"//g \
| sed s/"^ *input "//g \
| sed s/"type=radio "//g\
| sed s/"value=[a-z ]* "//g \
| sed s/"name="//g \
| sed s/"$"/" varchar(20) NOT NULL,"/g
echo "id int(5) NOT NULL auto_increment,
time timestamp(14) NOT NULL,
PRIMARY KEY  (id)
)"

And then called this script from a PHP page using passthru() ...and the
output is this:

CREATE TABLE GKVoteRESULTS (
required_src_sec varchar(20) NOT NULL,
required_src_sec varchar(20) NOT NULL,
required_src_sec varchar(20) NOT NULL,
required_gk_crc1 varchar(20) NOT NULL,
required_gk_crc1 varchar(20) NOT NULL,
required_gk_crc1 varchar(20) NOT NULL,
required_gk_crc2 varchar(20) NOT NULL,
required_gk_crc2 varchar(20) NOT NULL,
required_gk_crc2 varchar(20) NOT NULL,
required_gk_crc3 varchar(20) NOT NULL,
required_gk_crc3 varchar(20) NOT NULL,
required_gk_crc3 varchar(20) NOT NULL,
required_gk_cab varchar(20) NOT NULL,
required_gk_cab varchar(20) NOT NULL,
required_gk_cab varchar(20) NOT NULL,
required_male_vis varchar(20) NOT NULL,
required_male_vis varchar(20) NOT NULL,
required_male_vis varchar(20) NOT NULL,
id int(5) NOT NULL auto_increment,
time timestamp(14) NOT NULL,
PRIMARY KEY  (id)
)

Which is a good start.  However, you can see that I have duplicate
position names, which is bad. Anyone have any suggestions on how to
eliminate duplicate names inside a shell script?  Should I do some kind
of for or while loop, and have an array with values, and check against
the array with each new value?  Haven't tried using arrays in bash
scripts yet...

TIA

Jonathan Glass



---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be 
sent to listmaster at ale dot org.






More information about the Ale mailing list