LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Passing variables from AWK script to my shell script (http://www.linuxquestions.org/questions/programming-9/passing-variables-from-awk-script-to-my-shell-script-192252/)

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:

07:53
FÚTBOL
Fútbol mundial: Emisión 543

08:20
GOLF
Golf: Birdie: Emisión 329

08:45
INFORMATIVO
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!

Thanks

BL

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!

-Michael


All times are GMT -5. The time now is 03:21 AM.