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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:34:07+00:00 2026-05-15T04:34:07+00:00

How to delete all lines below a word except last line in a file.

  • 0

How to delete all lines below a word except last line in a file. suppose i have a file which contains

| 02/04/2010 07:24:20 | 20-24 |         26 |       13 |        2.60 | 
| 02/04/2010 07:24:25 | 25-29 |          6 |        3 |        0.60 | 
+---------------------+-------+------------+----------+-------------+

02-04-2010-07:24 --- ER GW 03

+---------------------+-------+------------+----------+-------------+
| date                | sec   | BOTH_MO_MT | MO_or_MT | TPS_PER_SEC |
+---------------------+-------+------------+----------+-------------+
| 02/04/2010 07:00:00 | 00-04 |         28 |       14 |        2.80 | 
| 02/04/2010 07:00:05 | 05-09 |         27 |       14 |        2.70 | 
...
...
...
...
END OF TPS PER 5 REPORT

and I need to delete all contents from “02-04-2010-07:24 — ER GW 03” except “END OF TPS PER 5 REPORT” and save the file.
This has to be done for around 700 files. all files are same format, with datemonthday filename.

  • 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-15T04:34:08+00:00Added an answer on May 15, 2026 at 4:34 am
    sed -ni '/ER GW/ b end; p; d; :end $p; n; b end' $file
    

    $file should be the filename. E.g.:

    for file in *.txt ; do
        sed -ni '/ER GW/ b end; p; d; :end $p; n; b end' $file
    done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do you delete all text above a certain line. For deletion below a
In order to delete all .svn files/folders/subfolders in myfolder I use this simple line
I want to delete all files in a directory with a given name, except
I have to delete all rows of a model with condition fkey_id = 1
I have a C file which I copied from somewhere else, but it has
I was trying to remove all comments and empty lines in a file with
We all know that wordpress have simple .htaccess code like below RewriteEngine on RewriteBase
How can I delete the whole lines which included both subStr1 and subStr2 in
Say I have element sequence like below : <div style=margin-bottom:9px;line-height:normal;margin-top:4px></div> <div style=margin-bottom:9px;line-height:normal;margin-top:4px>Something Here</div> <div
Is there a command to delete a line (or several lines) that is immediately

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.