Extracting lines from a text file based on another text file with line numbers | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Extracting lines from a text file based on another text file with line numbers

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-11-2012
evelibertine evelibertine is offline
Registered User
 
Join Date: May 2011
Last Activity: 27 December 2013, 6:16 PM EST
Posts: 193
Thanks: 94
Thanked 0 Times in 0 Posts
Extracting lines from a text file based on another text file with line numbers

Hi,

I am trying to extract lines from a text file given a text file containing line numbers to be extracted from the first file. How do I go about doing this? Thanks!
Sponsored Links
    #2  
Old 12-11-2012
elixir_sinari's Avatar
elixir_sinari elixir_sinari is offline Forum Advisor  
Gotham Knight
 
Join Date: Mar 2012
Last Activity: 16 July 2014, 3:22 PM EDT
Location: India
Posts: 1,412
Thanks: 100
Thanked 495 Times in 472 Posts
Assuming that your lines_file contains each line number on a separate line (and that you don't want to consider duplicate line numbers, if they exist):

Code:
awk 'FNR==NR{a[$1];next}FNR in a' lines_file data_file

The Following User Says Thank You to elixir_sinari For This Useful Post:
evelibertine (12-11-2012)
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Extracting Multiple Lines from a Text File MrDumbQuestion Shell Programming and Scripting 4 12-20-2011 09:10 AM
Extracting rows from a text file based on the first column evelibertine UNIX for Dummies Questions & Answers 1 09-19-2011 08:15 PM
Extracting rows from a text file based on the first column evelibertine UNIX for Dummies Questions & Answers 1 08-17-2011 05:53 PM
extracting unique lines from text file soliberus Shell Programming and Scripting 3 08-22-2008 10:18 AM
Extracting data from text file based on configuration set in config file suparnbector Shell Programming and Scripting 3 08-10-2007 02:25 AM



All times are GMT -4. The time now is 04:33 AM.