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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:16:43+00:00 2026-05-22T03:16:43+00:00

Is there a canonical way of doing that? I’ve been using head -n |

  • 0

Is there a “canonical” way of doing that? I’ve been using head -n | tail -1 which does the trick, but I’ve been wondering if there’s a Bash tool that specifically extracts a line (or a range of lines) from a file.

By “canonical” I mean a program whose main function is doing that.

  • 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-22T03:16:43+00:00Added an answer on May 22, 2026 at 3:16 am

    head and pipe with tail will be slow for a huge file. I would suggest sed like this:

    sed 'NUMq;d' file
    

    Where NUM is the number of the line you want to print; so, for example, sed '10q;d' file to print the 10th line of file.

    Explanation:

    NUMq will quit immediately when the line number is NUM.

    d will delete the line instead of printing it; this is inhibited on the last line because the q causes the rest of the script to be skipped when quitting.

    If you have NUM in a variable, you will want to use double quotes instead of single:

    sed "${NUM}q;d" file
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm wondering if there is a more canonical way to do this in ruby
Is there a canonical way to randomize an array in Objective-C?
Is there a canonical way to test to see if the process has administrative
In Rails, is there a canonical way of giving different views of the same
There's a Rails 3.2.3 web application which doesn't use any database. But in spite
In Java, is there a way (at runtime) to obtain the bytecode which defined
Is there any canonical way to measure the performance of a CATiledLayer on iOS?
Is there a canonical way to check the size of a file in Windows?
Is there any canonical straight way of enabling protobuf-net serialization on .NET 4 WCF?
is there a canonical way to partition a table by referenced data to another

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.