LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Extract only specific part from a file (https://www.linuxquestions.org/questions/linux-newbie-8/extract-only-specific-part-from-a-file-4175537667/)

babyPen 03-23-2015 11:02 PM

Extract only specific part from a file
 
Hello All,

I would like to know if there is a better way to achieve the below task:

Task: Copy lines 10 to 50 from a files that contains 100 lines.

My approach:
1st) use head command and then list first 50 lines and then tail last 40 lines.

2nd) Do a while loop with a counter and then when counter reaches to 10 start writing it to another file up to the point where the counter is 50 and then exit.

I would like to know if there are any other simple and straight approach using which I can directly copy lines 10 to 50.

Help and suggestions on this question are greatly appreciated.

Thanks.

veerain 03-23-2015 11:14 PM

Perhaps not. You can also use perl/python/ruby or any other script interpreter for doing it. Or you can make a generic 'C' executable for doing it so that it's useful for general purpose use.

syg00 03-23-2015 11:36 PM

Probably sed is simplest - see the manpage for address range usage.

grail 03-24-2015 02:12 AM

Agreed, sed would be the simplest. awk, perl and others can also easily perform the task.


All times are GMT -5. The time now is 10:08 PM.