|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Help with code
I have problem with this piece of code. I tried to use awk to send mail but it failed. Please help me Code:
for i in $( cat /tmp/a)
do
cat /tmp/b | grep $i | awk ' {mail -s " $2 is your new ID" $1@companydomain.com }
doneCode:
cat a Joe Mic Noah Cat b Alan 2313 Joe 223 Mic 768 Charlie 565 Noah 2656 |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Code:
cat /tmp/b | grep $i | awk ' {mail -s " $2 is your new ID" $1@companydomain.com }'No need to cat and grep Code:
awk '$0~inp {mail -s " $2 is your new ID $1@companydomain.com" }' inp=$i /tmp/bNot sure if this work, but you do miss a final ' in your code |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
It is still not working
It gives me error ( invalid char @ in expression ) !! |
|
#4
|
|||
|
|||
|
Here are a couple of ways to do what you want: Code:
#!/bin/ksh
echo simplififed translation from given code
while read i
do grep $i /tmp/b | awk '{printf("echo mail -s \"%s is your new ID\" %s@companydomain.com", $2, $1)}' | ksh
done < /tmp/a
echo awk replacement
awk 'FNR == NR {
newID[$1] = $2
next
}
{ printf("echo mail -s \"%s is your new ID\" %s@companydomain.com\n",
newID[$1], $1);
}' /tmp/b /tmp/a | kshI use ksh and I added echo commands in several places so it will show what it will do rather than actually invoke mail to send messages. You'll need to change /bin/ksh in the first line of the script to the absolute pathname of a shell on your system that processes traditional Bourne shell command syntax (e.g., bash, ksh, or sh) to run the script and then remove echo from the awk printf() command after you verify that the script does what you want. Choose whichever code segment you prefer to use. They both should do what you want. The first segment is a simplified and corrected version of what it looked like you were trying to do. The second one produces the same results, but should be more efficient. |
| The Following 2 Users Say Thank You to Don Cragun For This Useful Post: | ||
jim mcnamara (01-09-2013), Sara_84 (01-10-2013) | ||
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Thanks Cragun . It's working now
|
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Go to a line of code , skip few lines of code | Paarth | Linux | 5 | 12-26-2012 10:31 AM |
| Block of code replacement in Java source code through Unix script | hareeshram | Shell Programming and Scripting | 2 | 01-30-2012 10:54 AM |
| If ‘922’ Code does not exist on ‘03’ Record, ‘901’ Code will be there instead, move ‘03’ R | sgoud | UNIX for Dummies Questions & Answers | 1 | 06-28-2011 01:55 PM |
| how i prepare a c++ code(c code) for implementing my own protocol format | amitpansuria | Programming | 1 | 09-06-2007 11:09 PM |
|
|