Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6191339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:44:44+00:00 2026-05-24T02:44:44+00:00

I have a template code: <html> <head> <title> My page </title> </head> <body> CODEWOULDCOMEHERE

  • 0

I have a template code:

<html>
<head>
<title> My page </title>
</head>
<body>
CODEWOULDCOMEHERE
</BODY>
</HTML>

And I have a shell script (ksh) that is suppose to generate some more code (to be placed in the CODEWOULDCOMEHERE palce).

I just don’t know how to place that code there… I tried sed, but it didn’t work… What’s the most robust way to do that?

Worth to say that the code generated is quite long…

thanks!

[EDIT]

What I’ve tried so far:

HTMLCODE=$(genReportStatCellHtml)
HTMLOUT=$(cat report_template.html|sed -e "s/CODEWOULDCOMEHERE/\'$HTMLCODE\'/g")

which yields: sed: 0602-404 Function s/GENERATEDHTMLCODE/\'a lot of html'/g cannot be parsed.

And:

HTMLCODE=$(genReportStatCellHtml)
HTMLOUT=$(cat report_template.html)
    echo ${HTMLOUT/CODEWOULDCOMEHERE/$HTMLCODE}

which yields: ./test.sh[8]: ${HTMLOUT/CODEWOULDCOMEHERE/$HTMLCODE}: 0403-011 The specified substitution is not valid for this command.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T02:44:46+00:00Added an answer on May 24, 2026 at 2:44 am

    A simple way of doing this is with here docs. This is what that looks like when entered interactively:

    $ cat <<EOF
    > Some literal content
    > You can do parameter expansion:
    > $PWD
    > as well as command expansion:
    > `date`
    > 
    > EOF
    Some literal content
    You can do parameter expansion:
    /tmp
    as well as command expansion:
    Fri Jul 29 13:36:10 CDT 2011
    $
    

    Or a shell script that does it

    #! /bin/sh
    cat <<EOF >output.txt
    Some literal content
    You can do parameter expansion:
    $PWD
    as well as command expansion:
    `date`
    
    EOF
    

    Edit: There’s not really a good way to use an external template file with nothing more than the basic abilities of the shell, but it’s pretty easy to do in other languages. Here’s a python one liner that’ll do it.

    We need to use a specific template key for the one-liner, so CODEWOULDCOMEHERE gets replaced by {0}.

    $ cat report_template.html 
    <html>
    <head>
    <title> My page </title>
    </head>
    <body>
    {0}
    </BODY>
    </HTML>
    
    $ echo "Heres the part that gets inserted" | python -c 'import sys; sys.stdout.write(file(sys.argv[1]).read().format(sys.stdin.read()))' report_template.html 
    <html>
    <head>
    <title> My page </title>
    </head>
    <body>
    Heres the part that gets inserted
    
    </BODY>
    </HTML>
    

    All together, your script would look something like this

    subst_template () {
        python -c 'import sys; sys.stdout.write(file(sys.argv[1]).read().format(sys.stdin.read()))' $1
    }
    
    genReportStatCellHtml | subst_template report_template.html > report.html
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following HTML code: <ul id='item-list'></ul> <button id='add-item'>Add Item</button> <script type='text/template' id='item-template'>
I have javascript code embedded inside a html template file. When I load this
I have some template code that I would prefer to have stored in a
I have a custom template for an expander that is close to the code
I have code that looks like this: template<class T> class list { public: class
I have a code that parses some template files and when it finds a
I have an XSL template that is a small section of an HTML email.
I have the following code: template <typename T> LuaCall& operator>>(T) { BOOST_STATIC_ASSERT(sizeof(T) == 0);
I have the following code: template <class T> struct pointer { operator pointer<const T>()
I have something like the following code: template<typename T1, typename T2, typename T3, typename

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.