![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
|
|
||||
|
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. |
|
||||
|
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
|
|
||||
|
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.. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|