Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
07-06-2017, 01:45 AM
|
#1
|
LQ Newbie
Registered: Jul 2017
Posts: 2
Rep:
|
Need to know how the CC is getting calculated in the below script
z="KK"
Spt=""
cc=""
count=0
defaultengine="00000"
echo "00000"",00000"",00000"",0000"",000"",00000"",0000"",00000"",00000">>/data/informatica/Services_2/CSASERVICES04/TgtFiles/escalate_data1.out
while read -r line; do
a=`echo "$line"|cut -d ',' -f 1`
b=`echo "$line"|cut -d ',' -f 2`
c=`echo "$line"|cut -d ',' -f 3`
d=`echo "$line"|cut -d ',' -f 4`
e=`echo "$line"|cut -d ',' -f 5`
f=`echo "$line"|cut -d ',' -f 6`
g=`echo "$line"|cut -d ',' -f 7`
h=`echo "$line"|cut -d ',' -f 8`
k=`echo "$h@mail.ad.ge.com"`
i=`echo "$line"|cut -d ',' -f 9`
t="KK"
echo $f>/data/informatica/Services_2/CSASERVICES04/TgtFiles/Echo_special_character.txt
pop=`sed 's/\^/\,/g' /data/informatica/Services_2/CSASERVICES04/TgtFiles/Echo_special_character.txt`
echo $pop>/data/informatica/Services_2/CSASERVICES04/TgtFiles/Echo_special_character.txt
pop=`sed 's/||/\$/g' /data/informatica/Services_2/CSASERVICES04/TgtFiles/Echo_special_character.txt`
if [ $z = $g -o $z = $t ]
then
Spt=$Spt"<tr>
<td> "$a" </td>
<td> "$c" </td>
<td> "$d" </td>
<td> "$e" </td>
<td> "$pop" </td>
<td> "$i" </td>
</tr>"
fi
if [ $z != $g -a $z != $t -o $a = $defaultengine ]
then
cc=$(printf '%s\n' "$cc" | awk -v RS='[,[:space:]]+' '!a[$0]++{printf "%s%s", $0, RT}')
cc="${cc%,*}"
cc=`echo $cc",307009431@mail.ad.ge.com,210026614@mail.ad.ge.com,502301326@mail.ad.ge.com,210077716@mail.ad.ge .com"`
echo "
<html>
<head>
<title>any title</title>
</head>
<body>
Hi, <br><br>
For your action below are the details
<table border='2'>
<tr>
<td> <B> ESN </B> </td>
<td> <B> Module </B> </td>
<td> <B> Keyword </B> </td>
<td> <B> Bucket </B> </td>
<td> <B> Comment </B> </td>
<td> <B> Priority </B> </td>
</tr>
"$Spt"
</table>
<br>
<br>
WIP Link:<A Href='sc.ge.com/*WIPanalytics'>WIP-ANALYTICS</A><BR><BR>
Regards <br>
MCRB Shop Team
</body>
</html>
" | mailx -s "$(echo -e "Engine Escalated\nContent-Type: text/html")" -c $cc $z
Spt="<tr>
<td> "$a" </td>
<td> "$c" </td>
<td> "$d" </td>
<td> "$e" </td>
<td> "$pop" </td>
<td> "$i" </td>
</tr>"
fi
z=$g
if [ $count = 0 ]
then
cc=$k
else
cc=$cc","$k
fi
count=$count+1
done </data/informatica/Services_2/CSASERVICES04/TgtFiles/escalate_data1.out
|
|
|
07-06-2017, 06:03 AM
|
#2
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 23,495
|
please use [code]here comes your script[/code] to keep formatting of your script (you can probably edit your original post).
From the other hand insert set -xv at the beginning of your script and you will see what's happening.
There are 5 cc=<something> lines found in this script, which one is unclear?
|
|
|
07-06-2017, 06:43 AM
|
#3
|
LQ Newbie
Registered: Jul 2017
Posts: 2
Original Poster
Rep:
|
Quote:
Originally Posted by Surya Venkata
z="KK"
Spt=""
cc=""
count=0
defaultengine="00000"
echo "00000"",00000"",00000"",0000"",000"",00000"",0000"",00000"",00000">>/data/informatica/Services_2/CSASERVICES04/TgtFiles/escalate_data1.out
while read -r line; do
a=`echo "$line"|cut -d ',' -f 1`
b=`echo "$line"|cut -d ',' -f 2`
c=`echo "$line"|cut -d ',' -f 3`
d=`echo "$line"|cut -d ',' -f 4`
e=`echo "$line"|cut -d ',' -f 5`
f=`echo "$line"|cut -d ',' -f 6`
g=`echo "$line"|cut -d ',' -f 7`
h=`echo "$line"|cut -d ',' -f 8`
k=`echo "$h@mail.ad.ge.com"`
i=`echo "$line"|cut -d ',' -f 9`
t="KK"
echo $f>/data/informatica/Services_2/CSASERVICES04/TgtFiles/Echo_special_character.txt
pop=`sed 's/\^/\,/g' /data/informatica/Services_2/CSASERVICES04/TgtFiles/Echo_special_character.txt`
echo $pop>/data/informatica/Services_2/CSASERVICES04/TgtFiles/Echo_special_character.txt
pop=`sed 's/||/\$/g' /data/informatica/Services_2/CSASERVICES04/TgtFiles/Echo_special_character.txt`
if [ $z = $g -o $z = $t ]
then
Spt=$Spt"<tr>
<td> "$a" </td>
<td> "$c" </td>
<td> "$d" </td>
<td> "$e" </td>
<td> "$pop" </td>
<td> "$i" </td>
</tr>"
fi
if [ $z != $g -a $z != $t -o $a = $defaultengine ]
then
cc=$(printf '%s\n' "$cc" | awk -v RS='[,[:space:]]+' '!a[$0]++{printf "%s%s", $0, RT}')
cc="${cc%,*}"
cc=`echo $cc",307009431@mail.ad.ge.com,210026614@mail.ad.ge.com,502301326@mail.ad.ge.com,210077716@mail.ad.ge .com"`
echo "
<html>
<head>
<title>any title</title>
</head>
<body>
Hi, <br><br>
For your action below are the details
<table border='2'>
<tr>
<td> <B> ESN </B> </td>
<td> <B> Module </B> </td>
<td> <B> Keyword </B> </td>
<td> <B> Bucket </B> </td>
<td> <B> Comment </B> </td>
<td> <B> Priority </B> </td>
</tr>
"$Spt"
</table>
<br>
<br>
WIP Link:<A Href='sc.ge.com/*WIPanalytics'>WIP-ANALYTICS</A><BR><BR>
Regards <br>
MCRB Shop Team
</body>
</html>
" | mailx -s "$(echo -e "Engine Escalated\nContent-Type: text/html")" -c $cc $z
Spt="<tr>
<td> "$a" </td>
<td> "$c" </td>
<td> "$d" </td>
<td> "$e" </td>
<td> "$pop" </td>
<td> "$i" </td>
</tr>"
fi
z=$g
if [ $count = 0 ]
then
cc=$k
else
cc=$cc","$k
fi
count=$count+1
done </data/informatica/Services_2/CSASERVICES04/TgtFiles/escalate_data1.out
|
I am struck at this to understand:
cc=$(printf '%s\n' "$cc" | awk -v RS='[,[:space:]]+' '!a[$0]++{printf "%s%s", $0, RT}')
|
|
|
07-06-2017, 07:08 AM
|
#4
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 23,495
|
ok. again, please use code tags (no quote) around your script.
printf is a bash builtin, and you can check
Code:
printf '%s\n' "$cc"
is just prints the content of the variable cc (together with a \n at the end).
| will send that text to awk.
the awk command consists of 2 parts:
Code:
-v RS='[,[:space:]]+'
sets the variable RS. RS is the [input] record separator, so this string will tell awk how to separate records (=originally those are the lines): a comma and a whitespace and may be repeated several times.
the next part is the script itself:
Code:
!a[$0]++{printf "%s%s", $0, RT}
here RT is the record terminator, see man page of awk about that.
a[$0] will store all the input lines (which are the email addresses - separated by comma), and ++ counts their occurrences. !a[$0]++ is a check and will be true if a[$0] is 0 or undef, so when a given email comes first (other instances will increment a[$0]. { print } will occur only if the check was true.
So this awk will remove duplicated email addresses - and the final result will be stored in cc again.
|
|
|
All times are GMT -5. The time now is 01:41 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|