Объедините много нагрудных текстовых файлов в один - PullRequest
0 голосов
/ 11 февраля 2020

У меня есть несколько отдельных файлов bibtex, которые выглядят следующим образом:

первый файл:

@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}
}

Как можно прочитать все они (они находятся по одному пути) и создайте новый файл, который будет просто вставкой всех их.

Пример ожидаемого вывода

@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}
  }

Ответы [ 2 ]

2 голосов
/ 11 февраля 2020

Отредактировано:

Я протестировал приведенный ниже код, и он объединяет несколько файлов в один:

Сначала извлеките все пути к файлам .bib (".", если они находятся в рабочий каталог, "path/to/directory/" или "/absolute/path/to/directory" в противном случае:

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

Затем, переберите файлы один за другим и добавьте их:

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")))

} 

Наконец, напишите объединенную строку в файл:

cat(combined_bib, file="combined_references.bib", "\n")
0 голосов
/ 11 февраля 2020

Вы можете объединить содержимое двух файлов вместе, как это

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

И записать новый файл так:

writeLines(big_bib, "big_bib.bib")
...