Sample Header Ad - 728x90

Unix : How to convert HTML output from Shell script

0 votes
0 answers
778 views
How to display the sql query output to HTML table format output. am having shell script code to display output as html table format. and input is taken form sql query but am not getting the proper output. am getting the heading and data with unstructured it means it is taking the first column value only heading other displaying one by one format not displaying the table format. anyone help out to resolve this issue. Thanks in advance. This is my code : # SQL query to retrieve data from the custom table
#!/bin/bash

output_file="output.html"
temp_file="temp.txt"
delimiter="|"

sql_query="SELECT 'REQUEST_ID' AS \"REQUEST_ID\",
    'REQUESTED_BY' AS \"REQUEST_BY\",
    'USER_NAME' AS \"USER_NAME\",
    'REQUEST_DATE' AS \"REQUEST_DATE\",
    'CON_PRG_NAME' AS \"CON_PRG_NAME\",
    'OUTFILE_NAME' AS \"OUTFILE_NAME\",
    'FILE_MOVED_STATUS' AS \"FILE_MOVED_STATUS\",
    'CON_STATUS_CODE' AS \"CON_STATUS_CODE\",
    'ORG_ID' AS \"ORG_ID\"
    FROM DUAL
    UNION ALL
    SELECT TO_CHAR(request_id),
        TO_CHAR(requested_by),
        user_name,
        TO_CHAR(request_date),
        concurrent_program_name,
        outfile_name,
        file_moved_status,
        status_code,
        TO_CHAR(org_id)
    FROM xx_concurrent_stg
    WHERE concurrent_program_name = '$concurrent_program_name'
    AND request_date BETWEEN TO_DATE('$from_date', 'DD-MON-YY') AND TO_DATE('$to_date', 'DD-MON-YY');"

# Run the SQL query and save the output to a temporary file
sqlplus -S apps/apps@EBSDB  $temp_file
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SET COLSEP "$delimiter"
SET TRIMSPOOL ON

$sql_query

EXIT;
EOF

# Generate the HTML table from the temporary file
awk -v delimiter="$delimiter" '
BEGIN {
    print ""
    FS = delimiter
}
NR == 1 {
    print ""
    for (i = 1; i %s", $i
    }
    print ""
}
NR > 1 {
    print ""
    for (i = 1; i %s", $i
    }
    print ""
}
END {
    print ""
}' $temp_file > $output_file
Asked by Arthi (1 rep)
May 25, 2023, 11:22 AM
Last activity: May 25, 2023, 11:31 AM