Results 1 to 5 of 5
Greetings list.
So, I have a file ("linefile") with ~600 line numbers in one column, e.g.
92
1433
1725
1821
10265
etc.
I want to extract the lines with these ...
- 07-27-2009 #1Just Joined!
- Join Date
- Sep 2008
- Location
- Copenhagen
- Posts
- 5
Extract specific lines from a file using a list of line numbers from another file
Greetings list.
So, I have a file ("linefile") with ~600 line numbers in one column, e.g.
92
1433
1725
1821
10265
etc.
I want to extract the lines with these numbers from another file ("infile").
I think awk should be able to do the job, but can't figure out how. Any suggestions?
Cheers,
BBAF
- 07-27-2009 #2
yes, you are right. awk, (e)grep come to mind.
However, some more info is needed about the structure of that infile.
for example:
- do these numbers occur at the beginning of a line, when they occur?
- or do they occur in a certain row?
- do they occur before or after a certain char, i.e. "," or ":" ?
based on information like these, a RegularExpression can be created.
Right now, it's too vague.
Well ok, one can egrep for lines with numbers in it (like you wrote).
This would look like this:
egrep [0-9] infile
If there is at least one number in the line, it will match.
Regardless, where this number is or how often there is a number.
This is almost certain too much, I guess?
- 07-27-2009 #3Linux User
- Join Date
- May 2008
- Location
- NYC, moved from KS & MO
- Posts
- 251
How about
Code:for line in `cat linefile`; do sed -n "${line}p" infile; done
- 07-28-2009 #4Linux User
- Join Date
- Aug 2006
- Posts
- 458
use grep with -f option
Code:grep -f file1 file2
- 07-28-2009 #5Just Joined!
- Join Date
- Sep 2008
- Location
- Copenhagen
- Posts
- 5
[solved]
Thanks all for your replies.
Secondmouse, your suggestion solved the problem


Reply With Quote