Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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…

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now