Shell script to return all the ID's from file based on the distribution ID search


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Shell script to return all the ID's from file based on the distribution ID search
# 1  
Old 10-06-2006
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  
Old 10-06-2006
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 02:06 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Run shell script based on date file

Hi Team, I have a to run a script based on a date present in a different file which updates everyday. Kindly help with the solution. My current execution : ksh scriptname.sh 10152019. But here i want to enter this date from a file which gets updated daily. My appraoch : date file location:... (3 Replies)
Discussion started by: midhun3108
3 Replies

2. Shell Programming and Scripting

How to Search a string in a file in shell script?

I have a text file which is generated when the batch job is run. This batch may take few mins to run. When completed, the last line of the text file would be process completed. I need a shell script which will wait for this file till the process completed is printed in it, once found, it would move... (2 Replies)
Discussion started by: Lalat
2 Replies

3. Shell Programming and Scripting

File Count Based on FileDate using Shell Script

I have file listed in my directory in following format -rwxrwxr-x+ 1 test test 4.9M Oct 3 16:06 test20141002150108.txt -rwxrwxr-x+ 1 test test 4.9M Oct 4 16:06 test20141003150108.txt -rwxrwxr-x+ 1 test test 4.9M Oct 5 16:06 test20141005150108.txt -rwxrwxr-x+ 1 test ... (2 Replies)
Discussion started by: krish2014
2 Replies

4. Shell Programming and Scripting

Shell Script to Dynamically Extract file content based on Parameters from a pdf file

Hi Guru's, I am new to shell scripting. I have a unique requirement: The system generates a single pdf(/tmp/ABC.pdf) file with Invoices for Multiple Customers, the format is something like this: Page1 >> Customer 1 >>Invoice1 + invoice 2 >> Page1 end Page2 >> Customer 2 >>Invoice 3 + Invoice 4... (3 Replies)
Discussion started by: DIps
3 Replies

5. Shell Programming and Scripting

Query the table and return values to shell script and search result values from another files.

Hi, I need a shell script, which would search the result values from another files. 1)execute " select column1 from table_name" query on the table. 2)Based on the result, need to be grep from .wft files. could please explain about this.Below is the way i am using. #!/bin/sh... (4 Replies)
Discussion started by: Rami Reddy
4 Replies

6. Shell Programming and Scripting

bash script to find date based on search string for continuesly updating file

Hi All, I am very new to UNIX and I have tried this for a longtime now and unable to crack it.... There is a file that is continuously updating. I need to search for the string and find the date @ which it updated every day..... eg: String is "work started" The log entry is as below: ... (1 Reply)
Discussion started by: Nithz
1 Replies

7. Shell Programming and Scripting

Return to HTML file from shell script

Hi! I'm writing a simple script which I call on using a simple html button. The script also recives a simple argument. After the script is done I immediately want to return to my html page. But I dont know how to do that! #!/bin/sh echo "Content-type: text/html" echo "" if then echo... (1 Reply)
Discussion started by: crille
1 Replies

8. Shell Programming and Scripting

To search a file for a specific word in a file using shell script

Hi All, I have a sql output file has below. I want to get the values 200000040 and 1055.49 .Can anyone help me to write a shell script to get this. ACCOUNT_NO ------------------------------------------------------------ BILL_NO ... (8 Replies)
Discussion started by: girish.raos
8 Replies

9. Shell Programming and Scripting

Search flat file and return 3 fields

I need to be able to search a flat file (comma-separated values) for a specific value and then return the following 2 fields into variables. Here's a sample flat file: SN,Account,IPaddress W120394YF,adam,10.0.20.2 W394830PR,betty,10.0.20.3 W847582TD,charlie,10.0.20.4... (7 Replies)
Discussion started by: da2357
7 Replies

10. UNIX for Dummies Questions & Answers

Shell script to search for text in a file and copy file

Compete noob question.... I need a script to search through a directory and find files containing text string abcde1234 for example and then copy that file with that text string to another directory help please :eek: (9 Replies)
Discussion started by: imeadows
9 Replies
Login or Register to Ask a Question