-   Programming (
-   -   Passing variables from AWK script to my shell script (

BigLarry 06-11-2004 05:37 AM

Passing variables from AWK script to my shell script
Hi ppl,

I'm trying to do my first "real'" program in shell using wget,awk and sed. I'm knee deep in books and mans but am a little confused at the moment (arent we all :D )

OK, here is my program flow:

wget retrieves a web page from the internet and outputs the file to "file"

I then stip the html tags using sed :

#strip html tags from file
sed -e 's/<[^>]*>//g' file > done

I then remove some other unwanted stuff from the file, convert it to unix format and add blank line every third space. This gives me a file thus:

Fútbol mundial: Emisión 543

Golf: Birdie: Emisión 329

Noticias CNN+

etc etc

Now starting AWK in my shell script I do:

awk -f ESvar done > bloop

Where ESvar is an AWK script thus :

BEGIN { RS = "" ;FS = "\n";}

print $1 $2 $3


Works successfully but I need to use the $1 $2 and $3 variables from awk in my main shell script for things such as

sqlinsert = "insert into table (time,title,genre,date) values ($1,$2,$3,$date);"

and write this variable to a file and loop through it to create one big sql file I can then run at my mySQL db to insert the vaules.

I hope this makes (some) sense!



mparkhurs 06-12-2004 04:32 AM

I don't do (my)sql so I might not be much help.

However, it's my understanding that a variable can be redefined.

So it makes sense that if you use $1, $2, $3 in the script, as long as what they are holding is put whever you want it to do, you will have no problem when awk uses the variables, as it should store the new information. (Provided the old value of $1, etc is no longer needed by any other function in the script.)

Hope this helps!


All times are GMT -5. The time now is 05:48 PM.