Solved

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

Posted on 2007-03-17
2
241 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 50 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

739 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