LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-24-2015, 12:02 AM   #1
babyPen
LQ Newbie
 
Registered: May 2014
Posts: 17

Rep: Reputation: Disabled
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.
 
Old 03-24-2015, 12:14 AM   #2
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
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.
 
Old 03-24-2015, 12:36 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 14,838

Rep: Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822
Probably sed is simplest - see the manpage for address range usage.
 
Old 03-24-2015, 03:12 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,251

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


Reply

Tags
copy, linux, vi


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Extract some part of a file with specified time period in it? shivaa Linux - Newbie 4 11-01-2012 12:34 PM
to extract all the part of the filename before a particular word in the file aealexanderraj Linux - Newbie 3 08-27-2012 09:51 PM
to extract all the part of the filename before a particular word in the file aealexanderraj Linux - Newbie 1 08-27-2012 12:07 PM
extract specific content from file vaibhavs17 Linux - General 9 08-24-2011 03:41 PM
Extract part of file name himu3118 Programming 6 03-26-2010 09:52 AM


All times are GMT -5. The time now is 06:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration