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
Read the csv file and assign the values in to variable rajbal Shell Programming and Scripting 11 06-27-2009 01:17 PM
Assign Values to variables from a text file sarsani Shell Programming and Scripting 3 06-26-2009 07:05 PM
Post Shell programming: Question about source a file and read data from the file ccwq Shell Programming and Scripting 3 08-04-2007 10:28 PM
Cannot read variables after ssh with rc file (KSH) rockysfr Shell Programming and Scripting 0 07-03-2007 04:37 AM
How to Read a config file and Assign to Variable redlotus72 UNIX for Dummies Questions & Answers 1 11-13-2006 12:14 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-06-2008
akbar akbar is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 33
Awk/shell question: Read from file and assign to variables.

Is anyone able to help with writing a program that will do the following:

1. Read the contents of a file, line by line, and on each line, assign each of the two columns to a shell variable.

2. perform an action on the variables

3. Read the next line.

Here is what I've gotten so far. it doesn't work, and I only present it to give a better idea of what I am getting at:

for i in `cat inputfile|eval \`awk '{print "HOST="$1; print "PASS="$2;}'\``
do
echo "Action: host is $HOST and pass is $PASS"
echo
done



Any assistance is greatly appreciated
akbar
  #2 (permalink)  
Old 05-06-2008
akbar akbar is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 33
I think I've got a solution:

while read line; do
echo $line | eval `awk '{print "export HOST="$1; print "export PASS="$2;}'`
echo "Host is $HOST and PASS is $PASS"

done < $PASSLIST
  #3 (permalink)  
Old 05-06-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
how about
Code:
while read HOST PASS
do
      echo "HOST = $HOST  PASS = $PASS"
done < $PASSLIST
  #4 (permalink)  
Old 05-07-2008
akbar akbar is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 33
Quote:
Originally Posted by jim mcnamara View Post
how about
Code:
while read HOST PASS
do
      echo "HOST = $HOST  PASS = $PASS"
done < $PASSLIST
Excellent! Thank you.

akbar
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 08:33 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