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
Assign Values to variables from a text file sarsani Shell Programming and Scripting 3 06-26-2009 08:05 PM
Awk/shell question: Read from file and assign to variables. akbar Shell Programming and Scripting 3 05-07-2008 07:10 PM
Assign script parameters to variables giorgos193 Shell Programming and Scripting 16 04-15-2008 01:12 AM
how do u assign the values to different variables when it is presneted in one line?? SwetaShah High Level Programming 2 10-24-2005 10:56 PM
declare, assign variables using array, counter, loop egkumpe Shell Programming and Scripting 3 08-09-2004 11:56 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 Rating: Thread Rating: 1 votes, 4.00 average. Display Modes
  #1 (permalink)  
Old 09-23-2004
douknownam douknownam is offline
Registered User
  
 

Join Date: May 2004
Posts: 35
Assign variables with cut

I need to read a file (a list) and assign the value to a variable (for each line), I'm looping until the end of the file. My problem is, I want to assign 2 separate variables from the list. The process I'm using is:


Code:
awk '{print $3}' file1 > file2
awk '{print $4}' file1 > file3

cat file2 | while read var1
do
   cat file3 | cut -c2 | while read var2
      do
         if [[ "$var1" = "L" && "$var2" = "e" ]] then
            echo "Good Match" $var1

         elif [[ "$var1" = "T" && "$var2" = "t" ]] then   
            echo "Good Match" $var1
         else 
            echo "No Match" 

         fi
      done
done

It seems like my results are 2 running twice (reading the var2 twice), meaning the test runs separately for both tests.. I need to link up the variable lists in order to test both conditions at the same time (or dependant on one another). TIA.
  #2 (permalink)  
Old 09-23-2004
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,800
Just read the original file and discard some variables -
try:

Code:
   while read first second var1 var2 alltherest
      do
         if [[ "$var1" = "L" && "$var2" = "e" ]] then
            echo "Good Match" $var1

         elif [[ "$var1" = "T" && "$var2" = "t" ]] then   
            echo "Good Match" $var1
         else 
            echo "No Match" 
         fi
      done < file1

  #3 (permalink)  
Old 09-27-2004
douknownam douknownam is offline
Registered User
  
 

Join Date: May 2004
Posts: 35
thank you very much, I was not aware that we could assign 2 variables in that manner. Here is my code that works, for those who may run into this problem:


Code:
cat file | grep "M " > file1

awk '{print $3,$4}' file1 > file2

cat file2 | cut -c1,2,4 > file3

cat file3 | while read var1 var2  

do
   if [[ "$var1" = "L" && "$var2" = "e" ]] then
      echo "Good Match" $var1
   elif [[ "$var1" = "T" && "$var2" = "t" ]] then   
      echo "Good Match" $var1
   elif [[ "$var1" = "P" && "$var2" = "c" ]] then
      echo "Good Match" $var1 
   else 
      echo "No Match"
   fi
done


Last edited by douknownam; 09-27-2004 at 04:16 PM..
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 06: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