Hi, here is the on-going script.
#!/usr/bin/env perl use strict; use warnings; use Carp qw(croak); use autodie qw(open close); use File::Basename; croak "Usage: ./bibextract.pl tex_file.tex" unless defined $ARGV[0]; my $infile = $ARGV[0]; my $tex_file = $infile; my $bib_filename = "/home/lina/texmf/bibtex/bib/biophymd.bib"; my $bib_abbrev_filename = "/home/lina/texmf/bibtex/bib/biophyabbrev.bib"; my $extracted_bib = "basename($infile).bib"; my $cited; ## read all the cited items from .tex file and save it to $cited open my $fh, '<', $tex_file; while(<$fh>){ if(/cite\{(\S+)\}/){ $cited = sprintf "%s\n",$1; $cited =~ tr/\,/\n/; print $cited; } } close($fh); ## read the .bib database and extract the cited out open my $fh2, '<', $bib_filename; ####### Here I don't know how to end the while loop. while($cited){ while(my $line = <$fh2>){ print $line; #if ($line =~ $cited){ # print $line; #} } } $ more sample.tex aaa\cite{dehydron,dehydron1},ddd bbb\cite\cite{inhibitorAromaticDirect}aaa Thanks for your suggestions, Best regards, -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/