The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
grep unix.com with google



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 !!

Reply
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-24-2009
Registered User
 

Join Date: Nov 2009
Posts: 1
unix: extract a specific list of lines from a file

I would like to extract specific lines from a file and output them into another file.

Each line in the file has a unique ID, and I have a specific list of IDs (that are not consecutive) that I wish to extract.

for example:

1 aaaaaa bbbcb cccccc
2 aaaaaa bbbbb cccccd
3 aaaaaa bbbab cccccc
4 aaaaaa bbbxb cccccc
5 aaaaaa bbbbb cwcccc
6 aaaaaa bbbbb cqcccc

I wish to extract only lines 3 and 5 of this file, how do I do this?
  #2 (permalink)  
Old 11-24-2009
Registered User
 

Join Date: Nov 2009
Posts: 12
If the list of id-s is not very very very long, it could be as follows:
Code:
cat file | egrep "id1|id2|id3|...|idk"

It must take some precautions if you could find the strings of identifiers elsewhere in the line. For example, if the ID is the beginning of the line, you can do like this:
Code:
cat file | egrep "^id1|^id2|^id3|...|^idk"

Sponsored Links
Reply

Bookmarks

Tags
extract, lines

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell script or command help to extract specific contents from a long list of content patrick87 Shell Programming and Scripting 2 10-07-2009 10:11 PM
Extract lines of text based on a specific keyword DionDeVille Shell Programming and Scripting 4 08-14-2009 05:27 PM
extract the lines between specific line number from a text file return_user Shell Programming and Scripting 1 07-18-2009 10:11 PM
Extract specific lines for graphing genehunter UNIX for Dummies Questions & Answers 1 06-21-2009 01:51 AM
extract specific lines from file apalex UNIX for Dummies Questions & Answers 2 05-15-2001 10:57 AM



All times are GMT -4. The time now is 10:28 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0