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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:13:38+00:00 2026-05-28T14:13:38+00:00

First, I have what I believe to be a workable solution. However, test cases

  • 0

First, I have what I believe to be a workable solution. However, test cases
are one thing …reality is not always so kind. This is a “Does this look right?”
question …or, better, “Where might this fail? Suggest improvements?” question.

Problem:

Title should not creep past one line.

Test file:

You have a hold available for pickup as of 2012-01-13:
Title: Really Long Test Title Regarding Random Gibberish. Volume 1, A-B, United States
 and affiliated territories, United Nations, countries of the world
Author: Barrel Roll Morton
Copy: 3
#end-of-record
You have a hold available for pickup as of 2012-01-13:
Title: Short Catalogue of Random Gibberish. Volume 1, A-B, United States
Author: Skippy Credenza
Copy: 12
#end-of-record

Expected output:

You have a hold available for pickup as of 2012-01-13:
Title: Really Long Test Title Regarding Random Gibberish. Volume 1, A-B, United States
Author: Barrel Roll Morton
Copy: 3
#end-of-record
You have a hold available for pickup as of 2012-01-13:
Title: Short Catalogue of Random Gibberish. Volume 1, A-B, United States
Author: Skippy Credenza
Copy: 12
#end-of-record

My solution:

sed -e '/^Title/{N;/\nAuthor:/!{s/\n.*$//}}' test-file.txt

My logic re: above proposed solution

  • Look for regex /^Title/
  • Grab next line
  • If next line does not match /^Author/
  • Then search for regex /\n.*$/
  • Replace with nada.

Is there a more bullet proof way to do this?

  • 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-28T14:13:38+00:00Added an answer on May 28, 2026 at 2:13 pm

    That looks good, but if you don’t have control on how long that first line of text is, you can further truncate it using something like

    sed '/^Title/{N;/\nAuthor:/!{s/^\(....................\).*\n.*$/\1/;};}' test-file.txt
    

    (You don’t need the -e, but it doesn’t hurt either).

    I use an old-school sed, so I need the ;};} extra-bits.

    Adjust the number of ‘.’s in the match-pattern for the length of value you want to capture.

    Newer sed support curly-braced ranges, something like, cut I don’t have access to confirm.

    sed '/^Title/{N;/\nAuthor:/!{s/^\(.\{30,50\}\).*\n.*$/\1/;};}' test-file.txt
    

    Edit per @JonathanLeffler ‘s comment below. fixed range notation, change 30,50 to values that work for you.

    I hope this helps.

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

Sidebar

Related Questions

I have first names stored in one table and last names stored in another.
This is a followup/post question to another question; as I have discovered a solution
I am writing and implementation of the Miller-Rabin primality test. I believe I have
In order to bring up the menu for a DataGridViewComboBoxCell, I first have to
First I have a Listbox and set the DataSource to a MyObjectCollection MyObjectCollection implements
First I have a PHP file that gets data and file from a HTML
I have First/Last/Previous/Next buttons that change the selected child node of a TreeViewItem. Setting
I have first: select url from urls where site = '$value' order by url
I have a model that holds user address. This model has to have first_name
I have my first ever interview for a Java developer role, specifically RMI, Serverlets

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.