![]() |
|
|
grep unix.com with google
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Our Members | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 !! |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
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? |
|
|||
|
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 | ||
|
|
![]() |
| Bookmarks |
| Tags |
| extract, lines |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
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 |