I updated a bit to
sr/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_filename = "try.bib";
my $bib_abbrev_filename = "/home/lina/texmf/bibtex/bib/biophyabbrev.bib";
my $extracted_bib = "basename($infile).bib";
my $cited;
my @citeditems;
## 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/;
push(@citeditems,$cited);
}
}
close($fh);
## read the .bib database and extract the cited out
open my $fh2, '<', $bib_filename;
for (@citeditems){
my $item = $_;
while(my $line = <$fh2>){
if ($line =~ m/$item/){
print $line; ### strangely here nothing print it out.
}
}
}
Thanks ahead for your suggestions,
Best regards,
P. S.
$ more try.bib
@Article{ dehydron,
author = "L. F. Benoit and A. B. C",
title = "",
year = "2011",
journal = JPCHEMB,
volume = "15",
number = "2",
pages = "247-156",
doi = "10.1/jp65985"
}
@Article{ inhibitorAromaticDirect,
title = "",
author = "J. Hardy and D. J. Selkoe",
journal = SCIEN,
pages = "35-56",
volume = "29",
number = "580",
month = "Jul",
year = "2030"
}
@Article{ dehydron1,
title = "",
author = "G. E. and A. Wedemann",
journal = PEPT,
pages = "128-127",
volume = "2",
number = "9",
month = "Jul",
year = "2001"
}
$ more sample.tex
aaa\cite{dehydron,dehydron1},ddd
bbb\cite\cite{inhibitorAromaticDirect}aaa
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/