LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-12-2019, 01:12 AM   #1
Janani Priya
LQ Newbie
 
Registered: May 2019
Posts: 8

Rep: Reputation: Disabled
Conditional if in html tags


Hi ,

Please find my below html code,

#!/bin/bash


usage() { echo "Usage: $0 "'-d "your_input_data_delimiter_character" -t "My Title" -h "My Header"' 1>&2; exit 1; }

IFS_CHAR=$' \t\n'
MY_TITLE="MY_TITLE"
MY_HEADER="MY_HEADER"

while getopts "d:t:h:" inp; do
case "${inp}" in
d)
IFS_CHAR=${OPTARG};;
t)
MY_TITLE=${OPTARG};;
h)
MY_HEADER=${OPTARG};;
*)
usage;;
esac
done


# Compose the html file with the Header, Body ( Data ) and Footer

echo '<!DOCTYPE html>'
echo '<html>'
echo '<head>
<meta name="viewport" content="width=device-width, initial-scale=1" charset="ISO-8859-1">'
echo '<title>'$MY_TITLE'</title>'
echo '<script>
function myFunction(){
// Declare variables
var input, filter, table, tr, td, i;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("myTable");
tr = table.getElementsByTagName("tr");

// Loop through all table rows, and hide those who do not match the search query
for (i = 1; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td") ;
for(j=0 ; j<td.length ; j++)
{
var tdata = td[j] ;
if (tdata) {
if (tdata.innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
break ;
} else {
tr[i].style.display = "none";
}
}
}
}
}
</script>'

echo

echo '<style type="text/css">

table, th, td {
border: 1px solid black; // changing-colors
// word-wrap: break-word;
}

tr:first-child {
font-weight: bold;
}

tr:nth-child(even) {background: #eef} // changing-colors
tr:nth-child(odd) {background: #fee} // changing-colors

* {
box-sizing: border-box;
}

#myInput {
background-image: url("search.png");
background-position: left center;
background-repeat: no-repeat;
width: 94%;
font-size: 16px;
padding: 8px 20px 8px 40px;
border:2px solid Tomato; // changing-colors
margin-bottom: 18px;
}

#myTable {
border-collapse: collapse;
border: 1px solid #ddd; // changing-colors
width: 100%;
margin-top: 18px;
// Remove the // in front of the below two lines, to get fixed-width
// table-layout: fixed;
// word-wrap: break-word;
// font-size: 18px;
}

#myTable th, #myTable td {
text-align: left;
padding: 12px;
}

#myTable tr {
border-bottom: 1px solid #ddd; // changing-colors
}

#myTable tr:first-child:hover, #myTable tr:hover {
background-color: blueviolet; // changing-colors
}

#myTable tr:first-child {
background-color: blueviolet; // changing-colors
font-weight: bold;
font-style: helvetica;
}

</style>'

echo '</head>'

echo '<body>'

# changing-colors

echo '<h2 style="text-align:center;background-colorlum;color:cyan;">'$MY_HEADER'</h2>'

echo '<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search in all Fields...." title="Type in a Search String" autofocus="autofocus">'

echo '<table id="myTable">'


# the following 10 lines are commented by way of the first and last line characters. Please remove the first and last lines to get fixed-width of columns. Also, adjust the number of col lines and their values, to suit yur input data.
<< --MULTILINE-COMMENT--
echo '<col width="164" />
<col width="236" />
<col width="130" />
<col width="191" />
<col width="115" />
<col width="87" />
<col width="145" />
<col width="126" />'
--MULTILINE-COMMENT--

# the following 13 lines are commented by way of the first and last line characters. Please remove the first and last lines to get customized table header lines. Also, adjust the number of header lines and header data, to suit your input.
<< --MULTILINE-COMMENT--
echo '<tr class="header">'
echo '<th>Title</th>'
echo '<th>Description</th>'
echo '<th>Version</th>'
# echo '<th>Author</th>'
echo '<th>Original-site</th>'
echo '<th>License</th>'
echo '<th>Size</th>'
echo '<th>Extension_by</th>'
echo '<th>Tags</th>'
echo '</tr>'
--MULTILINE-COMMENT--

# Read the standard input data file contents into an Array, Check for URLs to Create Hyperlinks and
# Also Substitute html sensitive characters with proper syntax

cat /dev/stdin | sed '/^$/d' | while IFS=$IFS_CHAR read -ra line ; do
echo '<tr>'
for i in "${line[@]}"; do

# for hyperlinking a URL, first un-hash the for statement down below ( i.e. remove the starting # character ), save the file and run it as usual, to find out
# the column index number of the URL, then hash it as before and modify the
# index number in the if statement further down below ( currently :24 ) and
# un-hash all the statements below it, including the if statement, save the file and run it as usual, to make it to work

# for index in "${!line[@]}"; do printf "%s:%s\n" "$index" "${line[$index]}"; done

if [ -n "$i" ]; then
# if [[ ${line[@]:24:1} == "$i" && "$i" =~ ^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$ ]]; then
# if [[ ! ( "$i" =~ ^http.*:// || "$i" =~ ^ftp.*:// ) ]]; then
# i='http://'$i
# fi
# echo '<td><a href="'$i'" target="_blank">'Home Page'</a></td>'
# else
echo '<td>'$( echo $i|sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"'"'/\'/g' )'</td>'
# fi
fi
done
echo '</tr>'
done
echo '</table>'
echo

echo '</body>'
echo '</html>'



I want to check the vaule of a cell by using if condition, if the value == Healthy, the backgroung color of the cell should turn green color, and if its uhealthy , the bg color should chnage to red color,

P>S : I dont know where to append this condition in the above code. Thanks
 
Old 07-12-2019, 04:22 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,863
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Please edit your post, add the [code] and [/code] tags. Also your code is way too big, please try to create a minimal example.
 
1 members found this post helpful.
Old 07-12-2019, 12:16 PM   #3
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Quote:
Originally Posted by Janani Priya View Post
Hi ,

Please find my below html code,

#!/bin/bash
[snip]

I want to check the vaule of a cell by using if condition, if the value == Healthy, the backgroung color of the cell should turn green color, and if its uhealthy , the bg color should chnage to red color,

P>S : I dont know where to append this condition in the above code. Thanks
Firstly, that's completely unreadable. Please edit as requested in #2
Next, it's not html code, it's bash code that's echoing html
Third, there's no reference to "Healthy" in that code, and you're not telling us the value of what?

That said, the answer is to use an if statement. Please search for "bash if syntax" in your favorite search engine.

Edit: Is this homework? Looks like homework.

Last edited by scasey; 07-12-2019 at 12:17 PM.
 
1 members found this post helpful.
Old 07-12-2019, 12:22 PM   #4
WideOpenSkies
Member
 
Registered: May 2019
Location: /home/
Distribution: Arch Linux
Posts: 166

Rep: Reputation: 61
Quote:
Originally Posted by scasey View Post
Is this homework? Looks like homework.
Agreed.
 
Old 07-12-2019, 12:40 PM   #5
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,264
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
As you have been asked in your other threads, please place your code snippets inside [CODE]...[/CODE] tags. You may type those yourself or click the "#" button in the edit controls.

Also, please review the Site FAQ for guidance in asking well formed questions. Please reduce your code examples to a minimal example which reproduces your problem and refrain from posting whole code pages which is asking a bit much of others to read through to understand the question.

From that page...

Quote:
...understand that LQ is not a help desk, customer service line for a product you purchased or willing to do your homework (although we are happy to assist you with specifics, if you show some effort of your own!) We're a 100% volunteer organization that wants to help you help yourself.
 
  


Reply



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
ctags,tags and TAGS ,different inode,different file name,but seems same file hereisanan Linux - Server 5 05-14-2018 06:54 PM
[SOLVED] mp3 tags inconsistency between Linux and Sansa Fuze (mp3 tags editing software?) Hungry ghost Linux - Software 3 12-17-2012 08:09 PM
PHP & HTML conditional execution question bostonantifan Programming 1 05-19-2009 07:32 AM
After Editing Tags with JuK - XMMS do not display tags correctly Artik Linux - Software 0 07-23-2005 05:55 AM
regular expression for parsing html tags Bert Linux - Software 3 10-14-2002 04:31 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:24 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