'Merge many bib tex files into one

I have multiple single bibtex files which are like this:

first file:

@article{DBLP:journals/access/AlotaibiAASA20,
  author    = {Bashayer Alotaibi and
               Rabeeh Ayaz Abbasi and
               Muhammad Ahtisham Aslam and
               Kawther Saeedi and
               Dimah Alahmadi},
  title     = {Startup Initiative Response Analysis {(SIRA)} Framework for Analyzing
               Startup Initiatives on Twitter},
  journal   = {{IEEE} Access},
  volume    = {8},
  pages     = {10718--10730},
  year      = {2020},
  url       = {https://doi.org/10.1109/ACCESS.2020.2965181},
  doi       = {10.1109/ACCESS.2020.2965181},
  timestamp = {Fri, 07 Feb 2020 12:04:40 +0100},
  biburl    = {https://dblp.org/rec/journals/access/AlotaibiAASA20.bib},
  bibsource = {dblp computer science bibliography, https://dblp.org}
}

second file:

@inproceedings{DBLP:conf/comad/MathewKG020,
  author    = {Binny Mathew and
               Navish Kumar and
               Pawan Goyal and
               Animesh Mukherjee},
  editor    = {Rishiraj Saha Roy},
  title     = {Interaction dynamics between hate and counter users on Twitter},
  booktitle = {CoDS-COMAD 2020: 7th {ACM} {IKDD} CoDS and 25th COMAD, Hyderabad India,
               January 5-7, 2020},
  pages     = {116--124},
  publisher = {{ACM}},
  year      = {2020},
  url       = {https://doi.org/10.1145/3371158.3371172},
  doi       = {10.1145/3371158.3371172},
  timestamp = {Wed, 22 Jan 2020 14:37:05 +0100},
  biburl    = {https://dblp.org/rec/conf/comad/MathewKG020.bib},
  bibsource = {dblp computer science bibliography, https://dblp.org}
}

How is it possible to read them all (they are in the same path) and create a new file which will be just a paste of all of them.

Example of expected output

@article{DBLP:journals/access/AlotaibiAASA20,
    author    = {Bashayer Alotaibi and
                 Rabeeh Ayaz Abbasi and
                 Muhammad Ahtisham Aslam and
                 Kawther Saeedi and
                 Dimah Alahmadi},
    title     = {Startup Initiative Response Analysis {(SIRA)} Framework for Analyzing
                 Startup Initiatives on Twitter},
    journal   = {{IEEE} Access},
    volume    = {8},
    pages     = {10718--10730},
    year      = {2020},
    url       = {https://doi.org/10.1109/ACCESS.2020.2965181},
    doi       = {10.1109/ACCESS.2020.2965181},
    timestamp = {Fri, 07 Feb 2020 12:04:40 +0100},
    biburl    = {https://dblp.org/rec/journals/access/AlotaibiAASA20.bib},
    bibsource = {dblp computer science bibliography, https://dblp.org}
  }

  @inproceedings{DBLP:conf/comad/MathewKG020,
    author    = {Binny Mathew and
                 Navish Kumar and
                 Pawan Goyal and
                 Animesh Mukherjee},
    editor    = {Rishiraj Saha Roy},
    title     = {Interaction dynamics between hate and counter users on Twitter},
    booktitle = {CoDS-COMAD 2020: 7th {ACM} {IKDD} CoDS and 25th COMAD, Hyderabad India,
                 January 5-7, 2020},
    pages     = {116--124},
    publisher = {{ACM}},
    year      = {2020},
    url       = {https://doi.org/10.1145/3371158.3371172},
    doi       = {10.1145/3371158.3371172},
    timestamp = {Wed, 22 Jan 2020 14:37:05 +0100},
    biburl    = {https://dblp.org/rec/conf/comad/MathewKG020.bib},
    bibsource = {dblp computer science bibliography, https://dblp.org}
  }


Solution 1:[1]

Edited:

I tested the code below and it merges multiple files into one:

First, extract all paths to the .bib files ("." if they are in the working directory, "path/to/directory/" or "/absolute/path/to/directory" otherwise:

path_to_bib_files <- list.files(".", pattern="\\.bib$", full.names=TRUE)

Then, iterate through the files one by one and append them:

combined_bib <- ""
for (path_to_bib_file in path_to_bib_files) {

  fileCon <- file(path_to_bib_file)
  content <- readLines(fileCon)
  close(fileCon)

  combined_bib <- paste0(combined_bib, "\n", "\n", trimws(paste0(content, collapse="\n")))

} 

Finally, write the combined string to a file:

cat(combined_bib, file="combined_references.bib", "\n")

Solution 2:[2]

Here are the steps that worked from me.
1.List all files.

list_files<- list.files("path", pattern="\\.bib$", full.names=T)

2.Read all files

read_files<-lapply(d,readLines)

3.Unlist them

Unlist_files<-unlist(read_files)

4.Export as a single object

write(Unlist_files, file = "path/Bib.bib")

Solution 3:[3]

You can concatenate the contents of the two files together like this

big_bib <- c(readLines("bib1.bib"), "\n", readLines("bib2.bib"))

And write the new file like this:

writeLines(big_bib, "big_bib.bib")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 patL
Solution 3 Allan Cameron