?
Solved

Is there any command to get some lines from the middle of a text file?

Posted on 2007-03-17
2
Medium Priority
?
250 Views
Last Modified: 2013-12-16
Hi, everybody:
    Is there a command that can draw out some lines from a text file? As you know, 'head' and 'tail' commands can get lines from the beginning or end of a file. But, when I want to draw out lines from the middle of a file, what command can be used?
     Thanks.

                     tzk
0
Comment
Question by:tzk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 13

Accepted Solution

by:
Jeff Darling earned 150 total points
ID: 18742688

Try piping the head into the tail.

example:

If you have a text file named testt.txt that has 9 lines and you want to only see lines 3, 4 and 5 you could do it with tthis command sequence.

 head --lines=5 test.txt | tail --lines=3
0
 
LVL 48

Expert Comment

by:Tintin
ID: 18744759
or more simply with

sed -n 3,5p test.txt

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month8 days, 12 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question