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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Passing argument to a pl/sql block er_ashu Shell Programming and Scripting 2 05-02-2008 08:42 AM
Passing more than one argument in a function jisha Shell Programming and Scripting 1 04-23-2008 03:05 AM
passing argument into awk prkfriryce Shell Programming and Scripting 4 02-01-2007 12:44 PM
Problem with Argument Passing A_Rod Shell Programming and Scripting 4 09-13-2006 08:47 AM
Passing argument from one script to other lloydnwo Shell Programming and Scripting 3 10-27-2005 11:06 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-08-2008
Registered User
 

Join Date: Jan 2008
Location: Bangalore,India
Posts: 128
Arrow Argument passing using for or while loop

Hi All,

My query is as below:

Am basically writing a parser script.
My input file has got some variables which are populated by the calling program.

callig program:

fun1("cat","dog","cow")

input.*
argument[1] first
argument[2] second

I want to write a script that should give me the result as below when executed:

first="$1"
second="$2"

Forget about the calling function but the script i guess can be done using a for loop or a while, both am not at all comfortable with.

Can some one please help me in this.
Sorry for making the query so complicated.

Thanks in advance
JS
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-08-2008
Registered User
 

Join Date: Jan 2008
Location: Bangalore,India
Posts: 128
Am working on the same .. I came across the below query in awk.The fir loop is mentioned here just for the logic to understand.


for(i=0;i<=6;i++)
{
awk '/param/ {print $2"=\"$""\"" }' a.txt > we.txt
}

I want the we.txt to look like
first="$1"
second="$2"

Using my query i can print only
first="$"
second="$"

How can i print the value of "i "inside the awk statement using the for loop or while ????
This is what i tried to explain above

Thanks
JS
Reply With Quote
  #3 (permalink)  
Old 04-08-2008
Registered User
 

Join Date: Feb 2008
Posts: 33
okay, i didnt understand your first post, but i think you need to pass i as a parameter inside awk.. so here goes:

for(i=0;i<=6;i++)
{
awk -v value_of_i=$i '/param/ {print $2"=\"$"value_of_i"\"" }' a.txt > we.txt
}
Reply With Quote
  #4 (permalink)  
Old 04-08-2008
Registered User
 

Join Date: Jan 2008
Location: Bangalore,India
Posts: 128
Hello ag79,

Thanks a lot for ur time.I ran the following query

for i in 1 2 3
do
awk -v value_of_i=$i '/param/ {print $2"=\"$"value_of_i"\"" }' a.txt > we.txt
done

But this gav me the result

first="$3"
second="$3"
third="$3"


but my out put should be

first="$1"
second="$2"
third="$3"

Is this possible?

Thanks
JS
Reply With Quote
  #5 (permalink)  
Old 04-08-2008
Registered User
 

Join Date: Jan 2008
Location: Bangalore,India
Posts: 128
Hi All,

I found a solution :

a=1
awk '/param/{a++;print $2"=\"$" a"\""}' a.txt > we

Thanks
JS
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:12 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0