in reply to awk 2 perl oneliner
Not a oneliner, but maybe slightly better readable...
#!/usr/bin/perl # create names lookup table from first file while (<>) { $names{$_} = 1; last if eof; } $/ = "\n>"; # set input record separator # scan second file while (<>) { print if /^>?(\w+\n)/ && $names{$1}; }
Usage:
$ ./extract.pl file1 file2 >output
Update: you could of course also make a oneliner out of it :)
$ perl -ne'$/eq"\n"?$nm{$_}++:/^>?(\w+\n)/&&$nm{$1}&&print;$/="\n>"if +eof' file1 file2 >output
Or (approaching the realms of golfing and obfu):
$ perl -ne'1..eof&&($/=">")?${$_}++:/.+\n/&${$&}&&print' file1 file2 > +output
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: awk 2 perl oneliner
by Anonymous Monk on Mar 06, 2010 at 18:14 UTC | |
by almut (Canon) on Mar 06, 2010 at 20:16 UTC | |
by space_agent (Acolyte) on Mar 07, 2010 at 12:57 UTC |