Solved

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

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
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…
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…

760 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

18 Experts available now in Live!

Get 1:1 Help Now