UrgentPlease: compare 1 value with file values eliminating special characters

Hi All,

I have file

i have values like
----
112
113
109
112
109

I have another file
cat supplierDetails.txt
-------------------------
112|MIMUS|krishnaveni@google.com
113|MIMIRE|krishnaveni@google.com
114|MIMCHN|krishnaveni@google.com
115|CEL|krishnaveni@google.com
108|UGEN|krishnaveni@google.com
109|SLAND|krishnaveni@google.com

I need to compare above values to this file first column values
like
if 112=112 then
i need to print MIMUS
like i need to validate above all values to this file,
I need it in loop

Please help me

Thanks
Krish.

awk -F"|" 'NR==FNR{arr[$0];next}$1 in arr{print $2}' file1 upplierDetails.txt

Regards

for val in `cat file1`
do
grep $val supplierList.txt | awk -F"|" '{print $1,$2}' 
done

Hi,

Once i got the values
i need to mail this result like
mail -s "Gateway messaging: $2" krish@google.com

is it possible

please answer it.

Thanks krish.

U can redirect the printed values to a file
i.e

grep $val file2 | awk -F"|" '{print $1,$2}' >>tempfile 

and later use

mailx  -s "Gateway messaging:" -r  krish@google.com < tempfile

i used mailx is not working

again i used this one
mail -s "Gateway : $2" $Email < $tempfile

it says that

exam5.sh: line 4: $tempfile: ambiguous redirect

Is there any other option

My requirement is
112|MIMUS|krishnaveni@google.com

if val =112
then i need to send mail to
subject:MIMUS mail to Krishnaveni@google.com

is it possible

if val=113
then i need to send mail to
subject=MIMIRE mail to krish@google.com

i need it like this

Can you help me how to do this.

thanks
krish.

You can try this out

awk -F"|" 'NR==FNR{arr[$0];next}$1 in arr{print $2;system("mail -s "$2" "$3"<<EOF")}' file1.txt supplierList.txt

Your error was most likely using a dollar sign $tempfile when the name of the file was just tempfile (at least in the example Shivdatta posted)

... Though, in fact you don't need a temporary file at all:

while read val
do
    awk -F"|" -v val="$val" '$0 ~ val{print $1,$2}' supplierList.txt
done <file1 | mailx  -s "Gateway messaging:" -r  krish@google.com

I cleaned up some other various crimes against humanity in that script (grep | awk, cat in backticks), some of my fixes might not work if you are on HP-UX or some other severely crippled platform; change them back if so.

Hi,

THis script works fine,
awk -F"|" 'NR==FNR{arr[$0];next}$1 in arr{print $2;system("mail -s "$2" "$3"<<EOF")}' file1.txt supplierList.txt

here no need of file1.txt file, i dont have list of values to validate
i have only one value need to validate
val=112, then i need to look into supplierList.txt file
then
subject:MIMUS and mail to krish@google.com

Please suggest me and help me. Its very urgent waiting for reply

Thanks
krish.

Perhaps I may suggest that you try the suggestion I posted before? Try it with val=112

awk -F"|" -v val="112" '$0 ~ val{print $2,$3}' supplierDetails.txt

Combining this with the earlier scripts, we might get something like

#!/bin/sh
awk -F"|" -v val="$1" '$0 ~ val{ system "mail -s '$2' '$3'" }' SupplierDetails.txt

You'd save this in a script file, mark it executable, and invoke it with the value you want (e.g. sendif 112)