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 6149829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:31:07+00:00 2026-05-23T19:31:07+00:00

Sorry but I am still stuck on this problem. I would like to insert

  • 0

Sorry but I am still stuck on this problem.
I would like to insert a paragraph before the first match of "<tr> <td nowrap valign="top"/paragraph"

So I use this code:

sed '0,/<tr>                                  <td nowrap valign="top"/ { s/<tr>                                  <td nowrap valign="top"/paragraph\nsd/g }' /var/www/html/INFOSEC/english/news/test.html

However, the program returns me the whole page of that HTML file and no insertion happens.

Also, I would like to insert some values in the variable in sed code; can I do that?

eg. sed -i 's/old/$new/g' file
  • 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-23T19:31:08+00:00Added an answer on May 23, 2026 at 7:31 pm

    To insert before a pattern, you have to make sure your pattern matches something in the file.

    jcomeau@intrepid:/usr/src/clusterFix$ cat test.html
    <tr> <td nowrap valign="top">blather blather blather</td></tr>
    jcomeau@intrepid:/usr/src/clusterFix$ sed  '/<tr> *<td nowrap valign="top"/i<p>this is a new paragraph</p>' test.html
    <p>this is a new paragraph</p>
    <tr> <td nowrap valign="top">blather blather blather</td></tr>
    

    The “*” above matches any amount of spaces. Maybe that is what’s causing your command to fail. Of course you need the “-i” switch if you want to edit the file in-place.

    For the second question, sed -i 's/old/$new/g' file, that is almost right except you need to use double-quotes (") instead of single-quotes (') in order for string interpolation to work: sed -i "s/old/$new/g" file

    See http://www.linuxtopia.org/online_books/linux_tool_guides/the_sed_faq/sedfaq4_004.html from How to use sed to replace only the first occurrence in a file? for syntax on replacing only the first match.

    jcomeau@intrepid:/tmp$ cat test.txt 
    this is not the test
    this is not the test
    this is a test
    this is a test
    this is a test
    this is a test
    this is a test
    this is a test
    jcomeau@intrepid:/tmp$ sed '0,/\(this is a test\)/s//before first match\n\1/' test.txt
    this is not the test
    this is not the test
    before first match
    this is a test
    this is a test
    this is a test
    this is a test
    this is a test
    this is a test
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of I'm very sorry but this questions is not so so specific. All
Sorry if this seems like a dumb question but I am just learning bash
I'm sorry, but this is beginning to feel like kicking myself in the head.
Sorry if this sounds like a bit of a noobie question, i'm still relatively
sorry but i'm still struggling to make this code working. It works if with
Ok so sorry for being, I guess, a bit off topic but still I
Sorry for the simple question but I feel like there's a smarter way to
I'd like to add core data to an existing iPhone project, but I still
Guys, sorry for the basic question. I try to find out but I still
I am asking this question because of Zend Framework. I really like it but

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.