How to do an array?

D

Dave Kelly

I am going to ask this here. Part belongs in this users group and part
in another.
I have a html file that consists of several hundred lines such as the
group below.
To store the data on the server, am I correct to say an array is created
and for
this example the array has a name of 'describe[]'?

<div style="text-align: center;"><h2>Personal Data</h2></div>
<p>Your Name:&nbsp;&nbsp;<input type=text name=describe[] size="40%"
maxlength=256>
Tel:&nbsp;&nbsp;<input type=text name=describe[] size="30%" maxlength=16>
Date of Report:&nbsp;&nbsp;<input type=text name=describe[] size="10%"
maxlength=16></p>
<p>Your Address:&nbsp;&nbsp;<input type=text name=describe[] size="60%"
maxlength=1024>
E-Mail:&nbsp;&nbsp;<input type=text name=describe[] size="30%"
maxlength=1024></p>
</body>

I need to fill the [] with a number. I had wanted to write a shell script
to do that. I have googled for 2 days and have yet to discover how
to increment a numerical variable in 'sed'.

Can someone help me or more importantly, tell me where the tutorial is
that will
answer these question.

TIA
Dave
 
M

mbstevens

To store the data on the server, am I correct to say an array is created
and for
this example the array has a name of 'describe[]'?

There are many ways to store things on a server, but all envolve writing
to files. What one language describes as an array another might describe
as a structure or list or something else. Your question about an array
has no general meaning given the data that follows.
<div style="text-align: center;"><h2>Personal Data</h2></div>
<p>Your Name:&nbsp;&nbsp;<input type=text name=describe[] size="40%"
maxlength=256>
Tel:&nbsp;&nbsp;<input type=text name=describe[] size="30%" maxlength=16>
Date of Report:&nbsp;&nbsp;<input type=text name=describe[] size="10%"
maxlength=16></p>
<p>Your Address:&nbsp;&nbsp;<input type=text name=describe[] size="60%"
maxlength=1024>
E-Mail:&nbsp;&nbsp;<input type=text name=describe[] size="30%"
maxlength=1024></p>
</body>

I need to fill the [] with a number. I had wanted to write a shell script
to do that. I have googled for 2 days and have yet to discover how
to increment a numerical variable in 'sed'.

What I *think* you *might* be trying to do is some kind of templating.
Forget sed. Use Perl or Python or Ruby templating facilities. Google
"perl template," "python template," etc.
 
C

Chris F.A. Johnson

I am going to ask this here. Part belongs in this users group and
part in another. I have a html file that consists of several hundred
lines such as the group below. To store the data on the server, am I
correct to say an array is created and for this example the array
has a name of 'describe[]'?

<div style="text-align: center;"><h2>Personal Data</h2></div>
<p>Your Name:&nbsp;&nbsp;<input type=text name=describe[] size="40%"
maxlength=256>
Tel:&nbsp;&nbsp;<input type=text name=describe[] size="30%" maxlength=16>
Date of Report:&nbsp;&nbsp;<input type=text name=describe[] size="10%"
maxlength=16></p>
<p>Your Address:&nbsp;&nbsp;<input type=text name=describe[] size="60%"
maxlength=1024>
E-Mail:&nbsp;&nbsp;<input type=text name=describe[] size="30%"
maxlength=1024></p>
</body>

I need to fill the [] with a number. I had wanted to write a shell script
to do that. I have googled for 2 days and have yet to discover how
to increment a numerical variable in 'sed'.

Use awk, not sed, e.g.:

awk 'BEGIN { n = 1 }
{ while ( sub(/[[][]]/,"[" n "]" ) ) ++n ; print }
' FILENAME > NEWFILE
 
D

Dave Kelly

Chris said:
I need to fill the [] with a number. I had wanted to write a shell script
to do that. I have googled for 2 days and have yet to discover how
to increment a numerical variable in 'sed'.

Use awk, not sed, e.g.:

awk 'BEGIN { n = 1 }
{ while ( sub(/[[][]]/,"[" n "]" ) ) ++n ; print }
' FILENAME > NEWFILE
Thanks Chris.............
Worked beautifully.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top