The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
does any one know free web server to embed in my app umen High Level Programming 4 03-18-2008 10:47 AM
Can anyone find a bug in this code?? shell script amon Shell Programming and Scripting 1 09-19-2006 03:11 AM
Capture Oracle return code in shell script Vikas Sood Shell Programming and Scripting 1 05-22-2006 06:32 PM
Store return code of shell script in oracle table sveera Shell Programming and Scripting 3 05-04-2005 02:25 PM
Hide code in shell script??? alan Shell Programming and Scripting 11 08-02-2003 12:33 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-27-2006
rajbal rajbal is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 19
How to embed shell script in a awk code

I have written a code to extract comma seperated values from a file and assign them to a variable inside awk code.i want to use one of these variable to be used in wget function i.e to pass the siteurl.How i can implement the shell command wget inside the awk for loop.code snippet is shown below.
Note:1.sitenames is a csv files name.

awk -F, '{split($0,ar,",");

for(i=0;i<1;i++)
{ siteurl=ar[1];
size=ar[2];
nkeys=ar[3];
print siteurl;
print size;
print nkeys;
# wget www.real.com -o test.txt
for(j=0;j<nkeys;j++)
{
k=4;
keywords=ar[k+j];
print keywords;
}
}
}' sitenames


regards,
Raj
  #2 (permalink)  
Old 09-27-2006
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
try this

Code:
system ( "wget www.real.com -o test.txt" )

  #3 (permalink)  
Old 09-28-2006
rajbal rajbal is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 19
Anbu,
The code which you sent is working but if i pass the siteurl as a variable it do not work.Any ideas how to make it read the value of the siteurl as variable.
I tried this but not working.

system ( "wget $siteurl -o test.txt" )

Regards,
Raj
  #4 (permalink)  
Old 09-28-2006
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
nawk -v site_url=$siteurl '{system ("wget " site_url " -o test.txt)}'
  #5 (permalink)  
Old 09-28-2006
rajbal rajbal is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 19
Hi Marikle,
First of all thank you for your prompt response. Its giving the following error:
testawk.sh: line 19: syntax error near unexpected token `('
testawk.sh: line 19: ` nawk -v site_url=$siteurl '{system ("wget " site_url " -o test.txt)}''




I am attaching the full code :
awk -F, '{split($0,ar,",");

for(i=0;i<1;i++)
{ siteurl=ar[1];
size=ar[2];
nkeys=ar[3];
print siteurl;
print size;
print nkeys;
# echo $nkeys;
nawk -v site_url=$siteurl '{system ("wget " site_url " -o test.txt)}'

# system ( "wget ${siteurl} -o test.txt" )
# wget www.rhapsody.com -o test.txt
for(j=0;j<nkeys;j++)
{
k=4;
keywords=ar[k+j];
print keywords;
}
}
}' sitenames


Let me know where i am doing wrong?/
Regards,
Rajesh
  #6 (permalink)  
Old 09-28-2006
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
Sorry, forgot to close the quote:


Code:
nawk -v site_url=$siteurl '{system ("wget " site_url " -o test.txt")}'

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:24 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0