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 > UNIX for Dummies Questions & Answers
.
google unix.com



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
Shell script to search for text in a file and copy file imeadows UNIX for Dummies Questions & Answers 9 11-12-2008 09:12 PM
shell script to search content of file with timestamps in the directory psychobeauty Shell Programming and Scripting 10 04-21-2008 05:37 AM
search for the contents in many file and print that file using shell script cdfd123 Shell Programming and Scripting 3 10-07-2007 10:17 PM
read or search the item in a file sequentially by position using unix shell script? lok UNIX for Dummies Questions & Answers 6 07-12-2006 06:53 AM
Korn Shell Script - Read File & Search On Values run_unx_novice Shell Programming and Scripting 2 06-15-2005 07:20 AM

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 10-06-2006
kumbhatalok kumbhatalok is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 1
Shell script to return all the ID's from file based on the distribution ID search

Hi,
Please help me out on this

I have to store some distribution lists(dl) in a file say mail.txt
Say the file format be
d1 = alok@yahoo.co.in;alvin@rediffmail.com;vijay@yahoo.com; & so on...
d2 = abhinav@gmail.com;dalpit@hotmail.com;garima@yahoo.com;& so on...
d3 = ....
& so on
Now what i want is-->if i pass a keyword say d2 in shell script then it should return me all the id's corrosponding to d2.

Can anybody lemme know how that can be done using shell script?
  #2 (permalink)  
Old 10-06-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
findKey.sh d1

findkey.sh:
Code:
#!/bin/ksh

key="${1}"

file='mail.txt'

while read currentKey eq addr
do
 [ "${currentKey}" = "${key}" ] && echo "[${addr}]"
done < "${file}"
or with awk:
Code:
nawk -v key=d1 -v FS=" *= *" '$1 == key {print $2}' mail.txt

Last edited by vgersh99; 10-06-2006 at 01:06 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 09:29 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