![]() |
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 |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| file Lookup using awk | jerome Sukumar | Shell Programming and Scripting | 1 | 08-30-2007 03:28 AM |
| getting particular text after grep from lookup file | napolayan | UNIX for Dummies Questions & Answers | 10 | 10-20-2006 10:52 AM |
| reverse lookup file problem | Westy564 | IP Networking | 2 | 01-09-2004 02:55 PM |
| file lookup | gillbates | UNIX for Dummies Questions & Answers | 6 | 12-12-2003 02:04 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Lookup with a file
Hi All,
i have a variable which has a value in it. RETAILER='JEWL' i have a text file. Name: file.txt file.txt ________ WLG 150 JEWL 60 CVS 240 FLN 120 WND 120 I am trying to write a korn script.the script, based on the value in the RETAILER will do a look up against the file.txt. if match found then return the corresponding value in the 2nd column in the file.txt. Eg: do a look up with RETAILER with file.txt. JEWL and JEWL (in file.txt) match found then return the value corresponding to JEWL in file.txt i.e 60. Eg2: RETAILER='WLG'. do a look up with file.txt and return 150. can anyone please help me. ( korn shell) Thanks & Regards pavi. |
|
||||
|
cat file.txt | awk '/JEWL/ {print $2}'
cat the file and pipe it to awk. Awk is a pattern/action language. The above simple script will look for the pattern JEWL and print the 60 that is the second feild of the row that begins with JEWL. So you can pull in a variable on the command line and then if that variable matches any of the first feilds of the file.txt file, then, print feild 2. try this on the command line so that you can see the above program string work. Then we can talk about translating the rest of the algorithm into ksh. -Douglas |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|