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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:26:18+00:00 2026-05-27T16:26:18+00:00

Given a file with the following contents: <root> <a></a> <b></b> </root> The command should

  • 0

Given a file with the following contents:

<root>
<a></a>
<b></b>
</root>

The command should output:

<root>
<a></a>
<b></b>

Things I’ve tried using the GNU Win32 port of sed:

Remove the last two lines.

This is fast, but it assumes </root> is the second to last line and will cause a bug if it’s not.

sed -e '$d' test.xml | sed -e '$d'

Substituting all occurrences of </root> with an empty string.

This works, but is slower than the first solution, and will break if there are nested <root> elements (unlikely).

sed -e 's|</root>||' test.xml

The file I’m dealing with can be large so efficiency is important.

Is there a way to limit sed substitution to the last occurrence in the file? Or is there some other utility that would be faster?

  • 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-27T16:26:19+00:00Added an answer on May 27, 2026 at 4:26 pm

    Using Perl with File::Backwards should be very fast (relative, I know, but still…). Perlfaq5 has a topic on going through a file backwards and removing lines. You can check for your pattern using this topic’s code as a starting point.

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

Sidebar

Related Questions

Given the following file: department=value1 location=valueA location=valueB department=value2 I use the following to load
Given the following Java code for generating a binary file: DataOutputStream out = new
Given the following code (it's supposed to write helloworld in a helloworld file, and
Given I have two File objects I can think of the following implementation: public
Given the following xml fragment: <Problems> <Problem> <File>file1</File> <Description>desc1</Description> </Problem> <Problem> <File>file1</File> <Description>desc2</Description> </Problem>
Given the URL (single line): http://test.example.com/dir/subdir/file.html How can I extract the following parts using
I am using vc2010 and I am trying to read contents of a file
Hi given the following Code: private void extractLink(ScriptFile file) throws SAXException, IOException, ParserConfigurationException, XPathExpressionException
Lets assume a xml file named data.xml with following content: <root> <record> <id>1</id> <name>test
Would appreciate some assistance i have a txt file witht he following contents: 1234|dog|apartment|two

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.