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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
passing values into logrotate?? imbiea Shell Programming and Scripting 1 06-09-2008 05:03 PM
passing variable values to awk command jerardfjay Shell Programming and Scripting 1 05-22-2008 04:48 PM
passing values from sql to shell script sachin.gangadha Shell Programming and Scripting 3 04-23-2008 12:11 AM
Passing values from SQR to UNIX seeuinoz UNIX for Advanced & Expert Users 2 08-24-2005 04:54 PM
Passing values out awk. gio123bg Shell Programming and Scripting 3 12-09-2003 01:32 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 07-19-2007
LisaS LisaS is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 59
scripting: multiple values from file passing to command

one of my colleagues has this question.
he has a command, C_CMD which accepts 4 variables, $1 $2 $3 $4
he wants to load up a file with multiple rows, one row per set of variables and then iteratively execute the command based on the content of the file.

example:
at the command line you'd issue:
C_CMD A1 B1 C1 D1
C_CMD A2 B2 C2 D2
C_CMD A3 B3 C3 D3

but he wants to have FILE_C with:
A1 B1 C1 D1
A2 B2 C2 D2
A3 B3 C3 D3

and then process this in a script to iteratively invoke C_CMD similar to how you would with a single variable like this
for $file in `cat \path\FILE_D`
do
D_CMD $file
done

can you assist? I thought I saw something similar here a few days ago but now cannot find it.

Lisa
  #2 (permalink)  
Old 07-19-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Lisa,
You are almost there:
Code:
while read mParms
do
  D_CMD $mParms
done < \path\FILE_D
  #3 (permalink)  
Old 07-19-2007
LisaS LisaS is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 59
Shell_Life
I may be a little dense here - is that an answer for my multiple variable example or for my single variable example?
you used my single var "names" and that's what is confusing me.
I was asking how to script the C_CMD $1 $2 $3 $4 example
if your answer does that, please excuse my thickheadedness - I will try it when I can login again.
  #4 (permalink)  
Old 07-20-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Lisa,
The single variable 'mParms' has all your parameters from each record
in your file.
  #5 (permalink)  
Old 07-20-2007
LisaS LisaS is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 59
yes, thank you - I could see that after I "slept on it"
what if I changed it up and needed to be able to reference them separately like
C_CMD $1 | grep $2 | grep -v $3 | lp -d$4

would I have to just parse them out of the one variable or is there a differen techinque to use in that case

(not that I'd write that stmt but just example of piping and passing them)
  #6 (permalink)  
Old 07-20-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
If you want to access each individual variable:
Code:
while read mVar1 mVar2 mVar3 mVar4
do
  echo "1 = "${mVar1}" 2 = "${mVar2}" 3 = "${mVar3}" 4 = "${mVar4}
done < input_file
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:42 AM.


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