[K12OSN] General bash and gawk question.

Larry Mateo LarryM at fsusd.k12.ca.us
Wed Apr 14 21:56:47 UTC 2004


Red Hat Linux release 7.3 (Valhalla)
Kernel: 2.4.18-3smp
GNU bash, version 2.05a.0(1)-release (i686-pc-linux-gnu)
GNU Awk 3.1.0

I'm new to shell  programming, and have a question to which I cannot find an answer despite my searching various manuals and the internet.

Is it possible to populate array variables from within the gawk portion of a bash script, and then make the array values accessible by succeeding lines outside of the gawk code but within the same bash script?

For example:

*** Start example script ***

#!/bin/sh

#Perform some initial shell commands
clear
blah
blahblah
blahblahblah

# Read some values from a file via gawk; placing them into an array
gawk '
        BEGIN { printf "Starting gawk portion of shell scipt..." }
         /match some pattern/
        {populate the array}
       END { printf "Completed gawk portion of shell script..."}
' someintputfile.txt

# Finished with the gawk code, now I want to use the values from within
# the array that was populated via gawk.
# Can this be done?

*** End example script ***

Thanks much.

Larry Mateo
Network Technician II
Fairfield-Suisun Unified School District
larrym at fsusd.k12.ca.us





More information about the K12OSN mailing list