![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
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 |
| extract column based on name | t27 | UNIX for Dummies Questions & Answers | 3 | 08-29-2007 01:04 PM |
| Select Record based on First Column | mgirinath | Shell Programming and Scripting | 8 | 07-16-2007 01:38 AM |
| Retrieve line from a file based on a value in specific column | efernandes | UNIX for Dummies Questions & Answers | 1 | 01-27-2007 11:04 AM |
| Select records based on search criteria on first column | shashi_kiran_v | UNIX for Dummies Questions & Answers | 2 | 12-02-2005 01:49 PM |
| filter based on column value | rraajjiibb | Shell Programming and Scripting | 2 | 05-25-2004 09:09 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
column based search
Hi,
I need to search one file based on the entry from another; eg. file1 has entries; 45654 34768 12345 File2 has entries 23234 somestring 4312 45654 somestring 34768 12345 somestring 45654 so I need to pick first entry in file1 which eg. '45654' and search for this entry only in 'column 1' of File2. Then save the 3rd entry (column 3) from the same line to a variable. (to be used later). Any help would be appreciated. |
|
||||
|
Column based search
Thanks for the responses guys.
But 'joining' isnt going to resolve my problem. What i am trying to do is to pick one item at a time from file1 and then search the corresponding entry in file2 and save the associated value in column3 of the file 2 in a variable X. $ cat file1 45654 34768 12345 $ cat file2 23234 somestring 4312 45654 somestring 34768 12345 somestring 45654 So e.g. my first entry in File1 is '45654'. The corresponding value in Column3 of File2 is 34768. So i wanted to save this value in a variable X. |
|
|||||
|
You can do something like that :
Code:
while read item1
do
X=$(awk -v value1="$item1" '$1 == value1 { print $3 }' file2)
done < file1
After having read the value in the variable X, what do you want to do ? If you don't want to update the file file2, the best way is to use the Shell_Life' solution ( item1=$1 and X=$2 ). |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|