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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:11:56+00:00 2026-06-17T10:11:56+00:00

With my shell script, when I run ./Test1 hello result . It is supposed

  • 0

With my shell script, when I run ./Test1 hello result.

It is supposed to take hello as standard input and result as standard output. The shell should remove any whitespace before <td>, </td>, and abc

So, I write the script this way

tr -d [:blank:] < $1
grep -r "<td>" $1 | sed -r 's/<td>//g' > $2
sed -r 's/<\/td>//g' $2
sed -r 's/abc//g' $2

However, when I run this command, the content of result file is exactly the same as the content of hello file (the only difference is the whitespace is removed)

The file hello content:

<td>hello</td>
  <td>hello</td>
    <td>hello</td>
<td>abc</td>
 <td>abc</td>

How do I get sed to apply the change to the target 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-06-17T10:11:58+00:00Added an answer on June 17, 2026 at 10:11 am

    If you want to store the changes from sed back to the file use the -i option:

    $ cat file
    <head>abc</head>
        <td>hello</td>
          <td>hello</td>
            <td>hello</td>
        <td>abc</td>
         <td>abc</td>
    <h1>abc</h1>
    
    $ sed -ni '/<td>/{s/^\s*//;s/abc//;s/<\/\?td>//g;p}' file
    
    $ cat file
    hello
    hello
    hello
    

    Edit: The regexp is clearer if we use a different separator with sed and use the extended regexp option -r:

    $ sed -r 's_</?td>__g' file
        hello
          hello
            hello
        abc
         abc
    

    The ? make the previous character optional so the / doesn’t have to be present making the regexp match <td> and </td> in one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have a shell script which should run based on the return of
I have a shell script file (run.sh) that contains the following: #!/bin/bash %JAVA_HOME%/bin/java -jar
Hey, I'd like to get a shell script to run everytime I unlock my
Is it possible to have a Perl script run shell aliases? I am running
I am using the wc utility in a shell script that I run from
Thanks For your Valuable support, Now i m able to run shell script in
In a shell script lets say i have run a command like this for
How can I run a shell script in Mac Os X at a certain
I am executing a shell script in which I run a sybase query which
I want to run a shell script on startup by google ,I found that

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.