UrgentPlease: compare 1 value with file values eliminating special characters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting UrgentPlease: compare 1 value with file values eliminating special characters
# 8  
Old 04-25-2008
Java

Quote:
Originally Posted by kittusri9
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

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

# 9  
Old 04-25-2008
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:

Code:
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.

Last edited by era; 04-28-2008 at 05:49 AM..
# 10  
Old 04-28-2008
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.
# 11  
Old 04-28-2008
Perhaps I may suggest that you try the suggestion I posted before? Try it with val=112

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

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

Code:
#!/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)

Last edited by era; 04-28-2008 at 07:35 AM.. Reason: Short script which actually sends the requested mail
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep a particular string from column eliminating characters at the end.

Hi, So basically I have this file containing query output in seperated columns. In particular column I have the below strings: news news-prio I am trying to grep the string news without listing news-prio aswell. I tried grep "$MSG_TYPE" , grep -w "$MSG_TYPE" , grep... (4 Replies)
Discussion started by: nms
4 Replies

2. Shell Programming and Scripting

Substitute special Characters into a file

Hi experts :) I need to replace special characters into a file , in the followiing way : " --> "" ' --> '' _--> \_ I tried with the sed command but I'm getting and error ksh: $: not found. ksh: $: not found. sed: Function s/\/\/ cannot be parsed. Any idea ? Thanks , KOLAS... (2 Replies)
Discussion started by: Kolas79
2 Replies

3. Shell Programming and Scripting

File containing special characters

Hello All, I am facing challenges in order to transfer a file from windows to unix box,the file contains a special character '×' ,now when I am transferring the file from windows to unix that special character converted to something else like 'Ã' ,another thing I have noticed that the hardware is... (1 Reply)
Discussion started by: prarat
1 Replies

4. UNIX for Dummies Questions & Answers

Eliminating entries based on relative values

I have posted this before but did not get much feedback. So I will try again. I need to remove sequences from a file based on values listed on a second file. The sequences file looks like this: Sequences.txt >Sample1 Freq 59 ggatatgatgatgaactggt >Sample1 Freq 54 ggatatgatgttgaactggt... (4 Replies)
Discussion started by: Xterra
4 Replies

5. Shell Programming and Scripting

Shell : eliminating zero values and printing

I have a log file containing the below data and should have the output file as below. and the output file should not contain any 0 values. Eg. It should not contain 0000000:0000000 in it. input.txt Media200.5.5.1 00010003:065D1202 Media100.5.5.2 7,588,666,067,931,543... (6 Replies)
Discussion started by: scriptscript
6 Replies

6. Shell Programming and Scripting

Compare values in two files. For matching rows print corresponding values from File 1 in File2.

- I have two files (File 1 and File 2) and the contents of the files are mentioned below. - I am trying to compare the values of Column1 of File1 with Column1 of File2. If a match is found, print the corresponding value from Column2 of File1 in Column5 of File2. - I tried to modify and use... (10 Replies)
Discussion started by: Santoshbn
10 Replies

7. HP-UX

Eliminating characters between two expressions

Hi I have to eliminate all characters between ^ and a space in a file. Following lines - Test ^ H^@^@^@^@^@^@^B^VDM-BM-$|M-^_M-F^AM- File1 Test^H^@^@^@^@^@^F^A^X^@^SM-s^TM-3M-G^A File2 Should be printed as below Test File1 Test File2 I used sed '/^/,/ /d' command, but it is not working.... (1 Reply)
Discussion started by: arsheshadri
1 Replies

8. Shell Programming and Scripting

Removing special characters in file

I have file special.txt with the following data. <header info> 123$ty5%98&0asd 1@356fgbv78 09*&^5jkns43( ...........some more rows. In my output file, I want to eliminate all the special characters in my file and I want all other data. need some help. (6 Replies)
Discussion started by: srivsn
6 Replies

9. UNIX for Dummies Questions & Answers

How to delete a file with special characters

I don't now exactly how I did it, but I created a file named " -C " cexdi:/home1 $ls -lt total 1801336 -rw------- 1 cexdi ced-group 922275840 23 mars 10:03 -C How do I delete this file ? cexdi:/home1 $rm -C rm: invalid option -- C Syntax : rm filename ... Doesn't work...... (5 Replies)
Discussion started by: yveslagace
5 Replies

10. UNIX for Dummies Questions & Answers

how to see special characters in a file using vi

Hi, I have a file which has special characters. I can't see them when I "vi" the file. But I am sure there are some special un seen characters. How can I see them? Please help. Thx (6 Replies)
Discussion started by: jingi1234
6 Replies
Login or Register to Ask a Question