Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 06-11-2004, 05:37 AM   #1
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:

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!


Old 06-12-2004, 04:32 AM   #2
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!



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 > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:24 PM.

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