script question 
Author Message
 script question

Hi,
I need to parse an input file of the format
below and store the "index1- index-2" field
information in an array that I can use from
a ksh script.

Input file
index1-ralph index2-student   this is a student record
index1-anna  index2-engineer  an engineer record
.......

My main script is in ksh and I want to invoke
an awk command from it that parses out the
index1-ralph index2-student per line and puts
in an array that can be returned to my main script.
How do I do this? Each array element holds the information
for one line. I can't get this work ??? THANKS for any help!!!

#!/bin/ksh

awk ' /index1-*/ && /index2-*/ {arr[count]=$1$2; ++count} END
{ print arr} ' dat.file

# pseudocode next
while true
do
  process arr[i]
  i++
done

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Mon, 12 Aug 2002 03:00:00 GMT  
 script question
Try:

set $(awk '/index1-*/ && /index2-*/' dat.file)
while [ $1 ]
do
 echo $1 $2
 shift 2
done


Quote:

> Hi,
> I need to parse an input file of the format
> below and store the "index1- index-2" field
> information in an array that I can use from
> a ksh script.

> Input file
> index1-ralph index2-student   this is a student record
> index1-anna  index2-engineer  an engineer record
> .......

> My main script is in ksh and I want to invoke
> an awk command from it that parses out the
> index1-ralph index2-student per line and puts
> in an array that can be returned to my main script.
> How do I do this? Each array element holds the information
> for one line. I can't get this work ??? THANKS for any help!!!

> #!/bin/ksh

> awk ' /index1-*/ && /index2-*/ {arr[count]=$1$2; ++count} END
> { print arr} ' dat.file

> # pseudocode next
> while true
> do
>   process arr[i]
>   i++
> done

> Sent via Deja.com http://www.deja.com/
> Before you buy.

Sent via Deja.com http://www.deja.com/
Before you buy.


Tue, 13 Aug 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Pretty easy (I think) shell script question

2. URGENT: Shell scripting question

3. Shell script questions...

4. AWK script question

5. Scripting question

6. hugs scripting question

7. REXX OS2 Notify Script QUestion...

8. scripting question

9. scripting question

10. a script question

11. scripting question

12. Dumb Java Script Question

 

 
Powered by phpBB® Forum Software