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
foreach loop + 2 variables JamesGoh Shell Programming and Scripting 3 06-04-2008 04:36 AM
While loop with Multiple variables amit1_x Shell Programming and Scripting 4 04-02-2008 07:35 AM
using variables outside a while loop Tornado Shell Programming and Scripting 2 02-09-2007 01:26 AM
adding variables for, for loop jazz High Level Programming 3 03-13-2006 04:23 AM
Writing to variables within a loop Sniper Pixie UNIX for Dummies Questions & Answers 0 03-02-2006 09:11 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 02-11-2004
fosterian fosterian is offline
Registered User
  
 

Join Date: Feb 2004
Posts: 1
for loop with multiple variables ?

I have a script which selects two 'sets' of system LVM device files from a tabular file 'mapfile' using awk :

LIVELV=`awk '{print($1)}' mapfile`
BCVLV=`awk '{print($3)}' mapfile`

I wanted to pass these 'sets' into an LVM command 'loop' along the lines of :

lvmerge $BCVLV $LIVELV

ie. for each device file in column 1 of the file 'mapfile' merge in the device in column 3 of the same line.

I have messed about for hours with a for loop but I don't think this will handle the two different sets of variables in the same statement ?

I am probably approaching this from completely the wrong angle.

Any advice would be gratefully received - scripting isn't my strong suit - but god knows I'm trying !
  #2 (permalink)  
Old 02-11-2004
Perderabo's Avatar
Perderabo Perderabo is online now Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,126
You need a loop that loops on the elements from column one. Inside that loop, you need a 2nd loop for the elements in column 3.

Try to code it using that approach.
  #3 (permalink)  
Old 03-01-2004
karthi_tvr karthi_tvr is offline
Registered User
  
 

Join Date: Mar 2004
Location: Singapore
Posts: 5
Hi

You can achieve this by the following while loop :-

cat mapfile | while read next
do
LIVELV=`echo $next | awk '{print($1)}'`
BCVLV=`echo $next | awk '{print($3)}'`
lvmerge $BCVLV $LIVELV
done
  #4 (permalink)  
Old 03-01-2004
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
I would suggest :-

awk '{print $1, $3}' mapfile | while read LIVELV BCVLV
do
lvmerge $BCVLV $LIVELV
done
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 07:52 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