How to embed shell script in a awk code


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to embed shell script in a awk code
# 1  
Old 09-27-2006
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  
Old 09-27-2006
try this
Code:
system ( "wget www.real.com -o test.txt" )

# 3  
Old 09-28-2006
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  
Old 09-28-2006
nawk -v site_url=$siteurl '{system ("wget " site_url " -o test.txt)}'
# 5  
Old 09-28-2006
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  
Old 09-28-2006
Sorry, forgot to close the quote:

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

# 7  
Old 09-28-2006
still it shows the same error.I am not able to figure out why?/
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Embed text in C code

I hope c coding is ok here. I am fairly new at c coding. I simply want to embed some text in the executable. I tried this but can't find the text using Ghex. #include <stdio.h> const char * S = "andrew"; int main() { printf("Hello World!\n"); return 0; } (8 Replies)
Discussion started by: drew77
8 Replies

2. Shell Programming and Scripting

Embed image to the html script

hi, trying to embed an image to the html file to send out as an email. img src="data:image/jpeg;base64,$(base64 /home/test/abc.jpg but getting error as file not found after it aplies base64 on the file. (8 Replies)
Discussion started by: ATWC
8 Replies

3. Shell Programming and Scripting

How to embed sql query into our shell script?

Hi I would like to embed a sql query in my shell script. Also, before any the sql query is executed, i would like to validate username and password. (1 Reply)
Discussion started by: arghadeep adity
1 Replies

4. Shell Programming and Scripting

Unable to pass shell script variable to awk command in same shell script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk... (2 Replies)
Discussion started by: Ashunayak
2 Replies

5. Shell Programming and Scripting

How to capture the exit code of a shell script in a perl script.?

hi, i want to pop up an alert box using perl script. my requirement is. i am using a html page which calls a perl script. this perl script calls a shell script.. after the shell script ends its execution, i am using exit 0 to terminate the shell script successfully and exit 1 to terminate the... (3 Replies)
Discussion started by: Little
3 Replies

6. UNIX for Advanced & Expert Users

Embed tcl in ksh93 script

Hello everyone, I am trying to embed some tcl code inside a ksh93 script but I am not having any success. I even tried the simplest of code, something like this: . . jk=$(echo $(tcl << | write_file junkme "test"' | )) just to see if a file gets written. When I run there are no errors, but ... (3 Replies)
Discussion started by: gio001
3 Replies

7. Shell Programming and Scripting

How to embed commands in awk search

Hello; When I try: awk '/$(date "+%y\/%m\/%d")/,0' It errors with: awk: There is a regular expression error. Invalid pattern. Is there anyway to make this work ?? Thank you (2 Replies)
Discussion started by: delphys
2 Replies

8. Shell Programming and Scripting

Why can't embed commands like fg or bg in a shell script ?

Hi Can someone explain in an easy way that why can't embed commands like fg or bg in a shell script ? (4 Replies)
Discussion started by: qiulang
4 Replies

9. Web Development

php youtube style embed code

I'm looking to have a embed code for people be as short as possible. I'm trying to figure out how to do this. So something like... <EMBED SRC="http://www.website.com/myembedscript.php?id=1" HEIGHT=60 WIDTH=144> I'm looking to figure out what "myembedscript.php" should do. I have it... (0 Replies)
Discussion started by: mainegate
0 Replies

10. Shell Programming and Scripting

create a shell script that calls another script and and an awk script

Hi guys I have a shell script that executes sql statemets and sends the output to a file.the script takes in parameters executes sql and sends the result to an output file. #!/bin/sh echo " $2 $3 $4 $5 $6 $7 isql -w400 -U$2 -S$5 -P$3 << xxx use $4 go print"**Changes to the table... (0 Replies)
Discussion started by: magikminox
0 Replies
Login or Register to Ask a Question