LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-11-2004, 05:37 AM   #1
BigLarry
LQ Newbie
 
Registered: Jun 2004
Posts: 5

Rep: Reputation: 0
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 )

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
 
Old 06-12-2004, 04:32 AM   #2
mparkhurs
LQ Newbie
 
Registered: Jun 2004
Posts: 5

Rep: Reputation: 0
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing parameters to a shell script neocookie Linux - General 5 10-20-2005 11:44 AM
Passing arguments to a shell script subu_s Programming 3 09-02-2005 05:13 AM
Accessing Shell variable in awk script dileepkk Linux - General 1 10-07-2004 07:47 AM
script problem while using awk and passing varibales ulto Programming 6 04-23-2004 11:58 AM
passing quotes in shell script Tenor Trombone Programming 1 04-18-2001 09:26 PM


All times are GMT -5. The time now is 03:34 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration