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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:15:04+00:00 2026-06-14T23:15:04+00:00

I am downloading an XML file using wget, but sometime the file has text

  • 0

I am downloading an XML file using wget, but sometime the file has text in the first line that I need to get rid off.

It currently has “131” on the first line and “0” on the last line.

I need a way of removing these lines if it contains this information. I can’t do a perl find and replace, in-case it is not there but the proper first line contains “131”.

Does this make sense?

Any ideas?

Thanks

Example, sometimes it is this:

131
<element>
<example>content</example>
<example>content</example>
<example>content</example>
<example>content</example>
</element>
0

It is sometimes like this (correct)

<element>
<example>content</example>
<example>content</example>
<example>content</example>
<example>content</example>
</element>
  • 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-14T23:15:05+00:00Added an answer on June 14, 2026 at 11:15 pm

    That’s a job for sed! You would’nt find quicker or simplier:

    If you’re sure of the two values, you could simply:

    sed -e  '1{/^131$/d};${/^0$/d}' -i mybrokenfile
    

    But whith the following command, sed while remove any first and/or last line containing only a number:

    sed -e '1{/^[0-9]\+$/d};${/^[0-9]\+$/d}'
    

    This could by run with files as param and backup files auto-generation:

    sed -e '1{/^[0-9]\+$/d};${/^[0-9]\+$/d}' -i.bak files*
    

    Explained:

    • there is two parts, 1 and $ are address: 1 for first line and $ for last line.
    • Following block present another form of address-by-condition: /^[0-9]\+$/ mean *lines that begin with one or more characters between 0 and 9 and ending immediately after.
    • At this matching lines (on first or last line), the command to execute is d for delete line.

    This could be written:

    sed -e '1{
                /^[0-9]\+$/d
            }
            ${
                /^[0-9]\+$/d
            }' -i.bak files*
    

    as well.

    Edit:

    As I hate to write more than one time… approx anything;

    There is a way to do some tricky thing, but only on 1st and last line.

    First, the same sample could by written:

    sed -e '1ba;$ba;bb;:a;/^[0-9]\+$/d;:b;' -i.bak files*
    

    So this is 1 byte shorter! But especially the operation is written only once:

    Explained:

    • :a and :b are labels where to branch (jump) to
    • ba and bb are branch instruvtion respectively to :a and :b.
    • 1 and $ are address as previously described
    • /.../d is previously described too, mean delete lines matching regex

    And could by written:

    sed -e '
        1ba;
        $ba;
        bb;
       :a;
        /^[0-9]\+$/d;
       :b;
      ' -i.bak files*
    

    Sample of application, using s/../../ instead of only d:
    Modify version info only if present at 1st or last line:

     sed -e '1ba;$ba;bb;:a;s/\(Id: .*,v\).*\(Exp\)/\1'"$(
                 date +" $VER %F %T $USER ")"'\2/;b;' -i files*
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem is that, while downloading an XML file using ASIHTTPRequest it use default response
I need help with downloading from webserver... What i currently do is get XML
Im fetching a local xml file using jQuery ajax through an html that i
I have many XML-s and I downloaded using file or file_get_content, but the server
I am downloading an xml file from ftp and using the following code to
I am writing a script in php4 that downloads a xml file that has
I have thread where downloading xml file a this xml file i want to
I have 40 MB file in server and i am downloading my file using
So in my C# application I am downloading an XML file as a string,
I have an android app that feeds on an xml file that is generated

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.