Adding a blank line in between two O/Ps in tabular format which gets received over email


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Adding a blank line in between two O/Ps in tabular format which gets received over email
# 8  
Old 09-04-2017
Below is the content of mail.txt:

Code:
<table border=1>
<tr><td>CenterID        MIC     ExchangeName    CountryCode     EventDate       EventDayOfWeek  eventName</td></tr>
<tr><td>706     XTKS    Tokyo<\/td><td>Stock<\/td><td>Exchange  JP      20170811        Fri     Mountain<\/td><td>Day</td></tr>
</table><br>
<table border=1>
<tr><td>CenterID        MIC     ExchangeName    CountryCode     EventDate       EventDayOfWeek  eventName</td></tr>
<tr><td>903     XDFM    Dubai<\/td><td>Financial<\/td><td>Market        AE      20170831        Thu     El-Adha<\/td><td>1*</td></tr>
</table><br>

---------- Post updated 09-04-17 at 02:51 AM ---------- Previous update was 09-03-17 at 12:34 PM ----------

Hi,

So now Ia m getting the output as desired in the email. Below is the test script to check the format of the output over email:

Code:
#!/bin/bash

DT=(20170811 20170831)
for i in 0 1

do
#echo "<table border=1>"

mysql test -e "select c.CenterID,a.MIC,c.ExchangeName,a.CountryCode,a.EventDate,a.EventDayOfWeek,b.eventName from exch_calendar_event a left join exch_calendar_eventName b on a.EventID=b.ID left join exch_calendar_mic c on a.MIC=c.MIC where EventDate=DATE_FORMAT(${DT[$i]},'%Y%m%d') order by a.MIC;" | tr "\t" "~" > file.tmp

if [ -s file.tmp ]
then
  {
        echo "<table border=1>"
        while read -r LINE
        do
                LINE=$(echo $LINE|sed 's/~/<\/td><td>/g')
                echo "<tr><td>$LINE</td></tr>"
        done < file.tmp
        echo "</table><br><br>"
    } >> mail.txt
fi

done

cat header1 mail.txt footer | sendmail -t

And, following is the content in the mail.txt after execution of the script:

Code:
<table border=1>
<tr><td>CenterID</td><td>MIC</td><td>ExchangeName</td><td>CountryCode</td><td>EventDate</td><td>EventDayOfWeek</td><td>eventName</td></tr>
<tr><td>706</td><td>XTKS</td><td>Tokyo Stock Exchange</td><td>JP</td><td>20170811</td><td>Fri</td><td>Mountain Day</td></tr>
</table><br><br>
<table border=1>
<tr><td>CenterID</td><td>MIC</td><td>ExchangeName</td><td>CountryCode</td><td>EventDate</td><td>EventDayOfWeek</td><td>eventName</td></tr>
<tr><td>903</td><td>XDFM</td><td>Dubai Financial Market</td><td>AE</td><td>20170831</td><td>Thu</td><td>El-Adha 1*</td></tr>
</table><br><br>

So, now I need to modify the script to run the query to check, if there is any holiday in last 3 business days.

Thanks!!
# 9  
Old 09-04-2017
I'm pretty sure that topic has been covered, at least partly, in these fora before. Try searching for "business day", "holiday", or similar.
# 10  
Old 09-05-2017
Hi,

I tried t search, however, I am unable to find any relevant information about how to consider the business days only (mon-fri). I just need to run the query for last 3 business days (T, T-1, T-2). So we can this format in variables and use this in loop.

following is the code till now, where the hard coded dates are used to test the script, however, the script will be running everyday which will check, if today or T-1 or T-2 is a holiday. Note here that, this need to be checked for only business days.

Code:
#!/bin/bash

DT=(20170811 20170831)

for i in 0 1

do
#echo "<table border=1>"

mysql test -e "select c.CenterID,a.MIC,c.ExchangeName,a.CountryCode,a.EventDate,a.EventDayOfWeek,b.eventName from exch_calendar_event a left join exch_calendar_eventName b on a.EventID=b.ID left join exch_calendar_mic c on a.MIC=c.MIC where EventDate=DATE_FORMAT(${DT[$i]},'%Y%m%d') order by a.MIC;" | tr "\t" "~" > file.tmp

if [ -s file.tmp ]
then
  {
        echo "<table border=1>"
        while read -r LINE
        do
                LINE=$(echo $LINE|sed 's/~/<\/td><td>/g')
                echo "<tr><td>$LINE</td></tr>"
        done < file.tmp
        echo "</table><br><br>"
    } >> mail.txt
fi

done

cat header1 mail.txt footer | sendmail -t

# 11  
Old 09-06-2017
OK.. I sorted it out by myself. Below is the script:

Code:
day_of_week=`date +%w`

if [ `expr $day_of_week` == 1 ]
then
        today=`date +'%Y%m%d'`
        yes=`date -d "3 day ago" +'%Y%m%d'`
        dfy=`date -d "4 day ago" +'%Y%m%d'`


elif [ `expr $day_of_week - 1` == 1 ]
then
        today=`date +'%Y%m%d'`
        yes=`date -d "1 day ago" +'%Y%m%d'`
        dfy=`date -d "4 day ago" +'%Y%m%d'`

else

        today=`date +'%Y%m%d'`
        yes=`date -d "1 day ago" +'%Y%m%d'`
        dfy=`date -d "2 day ago" +'%Y%m%d'`
fi

#echo $today
#echo $yes
#echo $dfy


DT=($today $yes $dfy)
SEND=0
for i in 0 1 2

do

mysql test -e "select c.CenterID,a.MIC,c.ExchangeName,a.CountryCode,a.EventDate,a.EventDayOfWeek,b.eventName from exch_calendar_event a left join exch_calendar_eventName b on a.EventID=b.ID left join exch_calendar_mic c on a.MIC=c.MIC where EventDate=DATE_FORMAT(${DT[$i]},'%Y%m%d') order by a.MIC;" | tr "\t" "~" > file.tmp

if [ -s file.tmp ]
then
  {
        SEND=1
        echo "<br><b>T-$i (${DT[$i]})"
        echo "<table border=1>"
        while read -r LINE
        do
                LINE=$(echo $LINE|sed 's/~/<\/td><td>/g')
                echo "<tr><td>$LINE</td></tr>"
        done < file.tmp
        echo "</table><br>"
    } >> mail.txt
fi

done

[[ $SEND == 1 ]] && cat header1 mail.txt footer | sendmail -t
rm -f mail.txt file.tmp

Will post here, if any further help required.

Thanks!!
# 12  
Old 09-06-2017
Holidays are dependent on the location. I have no idea how to generally get them.

Regarding the redirection, it seems to make sense to make them even more global, redirecting the whole for-do-done block.
Then the artificial { } block can be omitted, and you can simply > (overwrite) the output file.
Code:
#!/bin/bash

DT=(20170811 20170831)

for i in 0 1

do
  #echo "<table border=1>"

  mysql test -e "select c.CenterID,a.MIC,c.ExchangeName,a.CountryCode,a.EventDate,a.EventDayOfWeek,b.eventName from exch_calendar_event a left join exch_calendar_eventName b on a.EventID=b.ID left join exch_calendar_mic c on a.MIC=c.MIC where EventDate=DATE_FORMAT(${DT[$i]},'%Y%m%d') order by a.MIC;" | tr "\t" "~" > file.tmp

  if [ -s file.tmp ]
  then
        echo "<table border=1>"
        while read -r LINE
        do
                LINE=$(echo $LINE|sed 's/~/<\/td><td>/g')
                echo "<tr><td>$LINE</td></tr>"
        done < file.tmp
        echo "</table><br><br>"
  fi

done > mail.txt

cat header1 mail.txt footer | sendmail -t

This User Gave Thanks to MadeInGermany For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To have a mail in tabular format

Hello Guys, developing a monitoring shell script to have my queue depth count over mail . here is the sample input file to the script which has all the queue names 1 : DISPLAY QUEUE(*) WHERE (CURDEPTH GT 0) ZFC8409: Display Queue details. QUEUE(QL.GVR.ATA.CACHE.01) ... (10 Replies)
Discussion started by: wims
10 Replies

2. Shell Programming and Scripting

Required to get out put of log in tabular format in email body

Dears Please support I have out put in text file and look like below fixed inquiries - Click on MAX suffix http://server:port/app User Details http://server:port/app Audit User Detail Action hhttp://server:port/app fixed inquiries - Click on MAX suffix http://server:port/app User Details ... (13 Replies)
Discussion started by: mirwasim
13 Replies

3. Shell Programming and Scripting

Script to generate Excel file or to SQL output data to Excel format/tabular format

Hi , i am generating some data by firing sql query with connecting to the database by my solaris box. The below one should be the header line of my excel ,here its coming in separate row. TO_CHAR(C. CURR_EMP_NO ---------- --------------- LST_NM... (6 Replies)
Discussion started by: dani1234
6 Replies

4. Shell Programming and Scripting

Displaying output in the tabular format

Hi I want to display the following input data into the tabular format as shown in the output. Input.txt: Following jobs are in pending state for more than 10 minutes: JOB_ID JOB_SUBMIT_ID MAHAR 784308 PUNJA 109367 Following jobs are running for longer time: JOB_ID... (1 Reply)
Discussion started by: dats
1 Replies

5. Shell Programming and Scripting

sed adding a blank line

I use the following as part of a script to correct for a faulty hostname file. # get the domain name read -r thehostname < /etc/hostname dom="$(echo $thehostname | cut -d'.' -f2)" numchar=${#dom} if then echo "It appears as though the hostname is not correctly set." echo "Hostname has... (5 Replies)
Discussion started by: bugeye
5 Replies

6. Shell Programming and Scripting

Adding a blank line after every 5th line

Hello... I have a file which contain certain number of records. I want to generate another file from this file which will contain 1st line as a blank line & after every 5 lines one blank line will be inserted. How to achieve this through shell scripting? Thanks... (5 Replies)
Discussion started by: 46019
5 Replies

7. Shell Programming and Scripting

Fill the empty line by adding line before blank line

FIle A "A" 2 aa 34 3 ac 5 cd "B" 3 hu 67 4 fg 5 gy output shud be A"" 2 aa 34 "A" 3 ac 34 "A" 5 cd 34 "B" 3 hu 67 "B" 4 fg 67 "B" 5 gy 67 (6 Replies)
Discussion started by: cdfd123
6 Replies

8. Shell Programming and Scripting

SED - adding blank line after each Range Match

the following range matching works great but i wish to add a blank line after each range result set... which i've tried and researched to no avail MY INPUT DATA: CURRENT CODE I'M USING: sed -n '/*$/,/;/p' $INPUT_FILE RESULTS I'M GETTING: RESULT I looking to... (5 Replies)
Discussion started by: danmauer
5 Replies

9. Shell Programming and Scripting

Need help in sed command (adding a blank line btw each block generated by pattern)

Hello friends, I have a C source code containing sql statements. I use the following sed command to print all the sql blocks in the source code.... sed -n "/exec sql/,/;/p" Sample.cpp The above sed command will print the sql blocks based on the pattern "exec sql" & ";"... (2 Replies)
Discussion started by: frozensmilz
2 Replies

10. UNIX for Dummies Questions & Answers

adding blank line in egrep

I followed the egrep example given in the thread "parse text or complex grep ?". It is exactly what I need...except... how do I insert a blank line after the second line? My exact command is: egrep 'patt1|patt2' filename the result is: patt1 patt2 patt1 patt2 and so on. I would... (2 Replies)
Discussion started by: antalexi
2 Replies
Login or Register to Ask a Question