The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
Passing argument to a pl/sql block er_ashu Shell Programming and Scripting 2 05-02-2008 11:42 AM
Passing more than one argument in a function jisha Shell Programming and Scripting 1 04-23-2008 06:05 AM
passing argument into awk prkfriryce Shell Programming and Scripting 4 02-01-2007 04:44 PM
Problem with Argument Passing A_Rod Shell Programming and Scripting 4 09-13-2006 11:47 AM
Passing argument from one script to other lloydnwo Shell Programming and Scripting 3 10-27-2005 02:06 PM

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 04-08-2008
jisha jisha is offline
Registered User
  
 

Join Date: Jan 2008
Location: Bangalore,India
Posts: 144
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
  #2 (permalink)  
Old 04-08-2008
jisha jisha is offline
Registered User
  
 

Join Date: Jan 2008
Location: Bangalore,India
Posts: 144
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
  #3 (permalink)  
Old 04-08-2008
ag79 ag79 is offline
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
}
  #4 (permalink)  
Old 04-08-2008
jisha jisha is offline
Registered User
  
 

Join Date: Jan 2008
Location: Bangalore,India
Posts: 144
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
  #5 (permalink)  
Old 04-09-2008
jisha jisha is offline
Registered User
  
 

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

I found a solution :

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

Thanks
JS
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 12:00 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