Solved

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

Posted on 2007-03-17
2
237 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 12

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
lunix and unix command 21 115
Using sort and uniq to pare down large syslog 6 72
Linux mount of Windows Shared Now Fails 8 111
SSL/TLS - openssl troubleshooting 3 58
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Fine Tune your automatic Updates for Ubuntu / Debian
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

740 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