LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 07-06-2017, 01:45 AM   #1
Surya Venkata
LQ Newbie
 
Registered: Jul 2017
Posts: 2

Rep: Reputation: Disabled
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
 
Old 07-06-2017, 06:03 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 23,495

Rep: Reputation: 7775Reputation: 7775Reputation: 7775Reputation: 7775Reputation: 7775Reputation: 7775Reputation: 7775Reputation: 7775Reputation: 7775Reputation: 7775Reputation: 7775
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?
 
Old 07-06-2017, 06:43 AM   #3
Surya Venkata
LQ Newbie
 
Registered: Jul 2017
Posts: 2

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Surya Venkata View Post
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}')
 
Old 07-06-2017, 07:08 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 23,495

Rep: Reputation: 7775Reputation: 7775Reputation: 7775Reputation: 7775Reputation: 7775Reputation: 7775Reputation: 7775Reputation: 7775Reputation: 7775Reputation: 7775Reputation: 7775
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Storage utilization calculated per user sharky Programming 7 11-14-2013 09:46 PM
[SOLVED] awk - how to join the string with calculated values kcapple Programming 15 05-15-2013 04:25 AM
pi calculated to record number. rich_c Linux - News 0 01-07-2010 07:03 PM
Accessing RTT values calculated by the kernel shrishailnk Linux - Networking 0 03-21-2008 10:30 AM
Msql - Updating calculated fields grabro Linux - Software 3 08-01-2007 12:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration