1

I use BibDesk to manage my references, including through auto-filing the corresponding PDF files on disk.

As a result, my .bib files contain several extra fields such as added/modified dates and encoded file paths, as in this example:

@article{xyz17, Author = {X, Y and Y, Z}, Date-Added = {2017-05-17 16:28:24 +0000}, Date-Modified = {2017-05-17 16:29:46 +0000}, Doi = {10.xxxx/xxx-2017-0001}, Journal = {Foo}, Keywords = {Bar}, Number = {1}, Title = {Hello World}, Year = {2017}, Bdsk-File-1 = {YnBsaXN0MDDUAQIDBAUG ... AAAAAAAAAAAAEIA==}}

Fortunately, BibDesk lets me export my .bib files as "minimal BibTeX" that contains only the essential fields:

@article{xyz17, Author = {X, Y and Y, Z}, Journal = {Foo}, Number = {1}, Title = {Hello World}, Year = {2017}}

I would like to be able to create such "minimal BibTeX" exports programmatically, through the command line. Thus my question:

Is there a command-line utility to save BibTeX files stripped down to a selection of fields?

Fr.
  • 259
  • 1
  • 10
  • 1
    You can always try sed – Marijn May 21 '17 at 17:08
  • From what? .... – cfr May 21 '17 at 23:29
  • @Marijn Thanks. I'll do my best to code up something myself, then :-) – Fr. May 21 '17 at 23:34
  • @cfr I'm sorry, but I don't get your comment. – Fr. May 21 '17 at 23:35
  • Save it from what? If you are in a GUI application, you aren't using the command line and that's where 'save' makes sense. Or in a non-GUI application, for that matter. So if you want a command line solution, you aren't in anything to save from. Hence, I assume you are talking about manipulating text files or something. But what's the input and what's the intended output? – cfr May 21 '17 at 23:38
  • @cfr Thanks for the clarification. The input is a .bib file, and the desired output is that same .bib file, minus a few fields. I'm experimenting with sed per @Marijn's recommendation, and it might well do the trick. – Fr. May 21 '17 at 23:43
  • @Fr. gawk or sed. – cfr May 22 '17 at 02:00
  • 1
    From one of the related questions (https://tex.stackexchange.com/a/87732/89417): you can also use biber standalone, that may be easier and more robust. – Marijn May 22 '17 at 07:57
  • Look at Gerd Neugebauer's BibTool. Speaking as a one-time BibDesk developer, I do not recommend using generic regex tools to munge BibTeX files. http://www.gerd-neugebauer.de/software/TeX/BibTool/en/ – Adam Maxwell May 22 '17 at 16:44
  • @AdamMaxwell Speaking as a one-time BibDesk user, I do not recommend using BibDesk to manage BibTeX files. – cfr Jun 01 '17 at 02:40
  • @cfr Your prerogative; I couldn't care less about your opinion of BibDesk. In my experience, people who recommend regexes to munge BibTeX are generally not aware of the variations in BibTeX syntax, and it will bite them. Use a tool with an actual lexer and parser, especially with a hand-edited file. – Adam Maxwell Jun 01 '17 at 02:48
  • @AdamMaxwell I wouldn't recommend them to manage .bib files (even though I effectively do), but for just removing unwanted fields from machine-generated files, effectively, I'd expect it to be relatively straightforward. But Biber would be my preferred tool. – cfr Jun 01 '17 at 03:41

1 Answers1

2

The comments on the question already provided these good solutions:

In addition to the previously mentioned solutions:

Big Mac
  • 410
  • @cfr Good idea, I've converted it! I would have just added to the comments, but I didn't have enough reputation to comment on the question. – Big Mac Jun 01 '17 at 02:47
  • @cfr In a comment on the question, you advised against BibDesk. Is there a GUI reference manager that you recommend? – Big Mac Jun 01 '17 at 03:36
  • I was being somewhat flippant. When I used it, I discovered its own developers said people shouldn't use it for, say, a dissertation. Since I was in the middle of my PhD at the time, that pretty much did it. I didn't like it because it messed up hand-edited files and wouldn't let me do things in a way that I wanted to do them to ensure consistency. I'm also reluctant to recommend any software which is platform-specific. JabRef has a good reputation, but I just use scripts (including the gawk and sed disparaged in the comments above) and my TeX editor. – cfr Jun 01 '17 at 03:45
  • @cfr If any BibDesk developer said that, it was a joke, and I regret the misunderstanding. Mike McCracken wrote BibDesk for use with his dissertation, and it's all I used when I was writing mine (though I fixed a few bugs in it along the way). Of course it alters hand-edited files, but consider that this mess @article( testcitekey , title="My Title", author={von Some{\"o}ne, Me},month=jun, year=2016 ) is valid BibTeX. It's nearly impossible to preserve idiosyncrasies of hand-edited BibTeX (preserving macros was hard enough). – Adam Maxwell Jun 01 '17 at 15:43
  • I can see why BibDesk is not for everyone, since it's Mac-only, but I've used BibDesk for a decade, and it's a beloved part of my personal knowledge management ecosystem. Since the data is just BibTeX that I know how to manipulate with numerous tools, I'm confident that I could switch to other software in the future if necessary. – Big Mac Jun 01 '17 at 22:32
  • @AdamMaxwell Ah. Well, it certainly put me off! I was alarmed and assumed it meant the application might lose all my data or something, so I figured I had to quit using it. Essentially, my scripts enforce sufficient consistency that I can apply ordinary text processing tools reasonably safely. (And it is all versioned, so I can always cycle back if necessary.) But I agree it would be hard to use them with arbitrary hand-edited files. As I say, Biber is really a nice tool for this. – cfr Jun 02 '17 at 11:15